From 4767ae218fd8db53d852352497eb636a7f26ef8f Mon Sep 17 00:00:00 2001 From: __apple <1991585851@qq.com> Date: Wed, 20 Mar 2019 16:37:28 +0800 Subject: [PATCH 1/2] Update persistent_storage_worker.go --- engine/persistent_storage_worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/persistent_storage_worker.go b/engine/persistent_storage_worker.go index 69835c5..66147f7 100644 --- a/engine/persistent_storage_worker.go +++ b/engine/persistent_storage_worker.go @@ -58,7 +58,7 @@ func (engine *Engine) persistentStorageInitWorker(shard int) { err := dec.Decode(&data) if err == nil { // 添加索引 - engine.internalIndexDocument(docId, data, false) + engine.IndexDocument(docId, data, false) } return nil }) From 06f5eb3de8f27a68ec21e6bdc592d7b1a7afdc5e Mon Sep 17 00:00:00 2001 From: __apple <1991585851@qq.com> Date: Wed, 20 Mar 2019 16:44:55 +0800 Subject: [PATCH 2/2] Delete persistent_storage_worker.go --- engine/persistent_storage_worker.go | 66 ----------------------------- 1 file changed, 66 deletions(-) delete mode 100644 engine/persistent_storage_worker.go diff --git a/engine/persistent_storage_worker.go b/engine/persistent_storage_worker.go deleted file mode 100644 index 66147f7..0000000 --- a/engine/persistent_storage_worker.go +++ /dev/null @@ -1,66 +0,0 @@ -package engine - -import ( - "bytes" - "encoding/binary" - "encoding/gob" - "github.com/huichen/wukong/types" - "sync/atomic" -) - -type persistentStorageIndexDocumentRequest struct { - docId uint64 - data types.DocumentIndexData -} - -func (engine *Engine) persistentStorageIndexDocumentWorker(shard int) { - for { - request := <-engine.persistentStorageIndexDocumentChannels[shard] - - // 得到key - b := make([]byte, 10) - length := binary.PutUvarint(b, request.docId) - - // 得到value - var buf bytes.Buffer - enc := gob.NewEncoder(&buf) - err := enc.Encode(request.data) - if err != nil { - atomic.AddUint64(&engine.numDocumentsStored, 1) - continue - } - - // 将key-value写入数据库 - engine.dbs[shard].Set(b[0:length], buf.Bytes()) - atomic.AddUint64(&engine.numDocumentsStored, 1) - } -} - -func (engine *Engine) persistentStorageRemoveDocumentWorker(docId uint64, shard uint32) { - // 得到key - b := make([]byte, 10) - length := binary.PutUvarint(b, docId) - - // 从数据库删除该key - engine.dbs[shard].Delete(b[0:length]) -} - -func (engine *Engine) persistentStorageInitWorker(shard int) { - engine.dbs[shard].ForEach(func(k, v []byte) error { - key, value := k, v - // 得到docID - docId, _ := binary.Uvarint(key) - - // 得到data - buf := bytes.NewReader(value) - dec := gob.NewDecoder(buf) - var data types.DocumentIndexData - err := dec.Decode(&data) - if err == nil { - // 添加索引 - engine.IndexDocument(docId, data, false) - } - return nil - }) - engine.persistentStorageInitChannel <- true -}