Skip to content
Snippets Groups Projects
Commit 8eac2743 authored by Ashwin's avatar Ashwin
Browse files

batch write while merging

parent 62b6b8fd
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"bytes" "bytes"
"container/heap" "container/heap"
"flag" "flag"
"fmt"
"io/ioutil" "io/ioutil"
"math" "math"
"path" "path"
...@@ -96,7 +97,8 @@ func mergeFolders(mergePath, destPath string) { ...@@ -96,7 +97,8 @@ func mergeFolders(mergePath, destPath string) {
opt.SetCreateIfMissing(true) opt.SetCreateIfMissing(true)
ropt = rocksdb.NewReadOptions() ropt = rocksdb.NewReadOptions()
wopt = rocksdb.NewWriteOptions() wopt = rocksdb.NewWriteOptions()
wopt.SetSync(true) wopt.SetSync(false)
wb := rocksdb.NewWriteBatch()
pq = make(PriorityQueue, 0) pq = make(PriorityQueue, 0)
heap.Init(&pq) heap.Init(&pq)
...@@ -134,6 +136,7 @@ func mergeFolders(mergePath, destPath string) { ...@@ -134,6 +136,7 @@ func mergeFolders(mergePath, destPath string) {
} }
var lastKey, lastValue []byte var lastKey, lastValue []byte
count := 0
for pq.Len() > 0 { for pq.Len() > 0 {
top := heap.Pop(&pq).(*Item) top := heap.Pop(&pq).(*Item)
...@@ -143,7 +146,12 @@ func mergeFolders(mergePath, destPath string) { ...@@ -143,7 +146,12 @@ func mergeFolders(mergePath, destPath string) {
Fatal("different value for same key") Fatal("different value for same key")
} }
} }
db.Put(wopt, top.key, top.value) wb.Put(top.key, top.value)
count++
if count%1000 == 0 {
db.Write(wopt, wb)
wb.Clear()
}
lastKey = top.key lastKey = top.key
lastValue = top.value lastValue = top.value
...@@ -158,6 +166,11 @@ func mergeFolders(mergePath, destPath string) { ...@@ -158,6 +166,11 @@ func mergeFolders(mergePath, destPath string) {
} }
heap.Push(&pq, item) heap.Push(&pq, item)
} }
db.Write(wopt, wb)
wb.Close()
fmt.Println("Count : ", count)
} }
func main() { func main() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment