Browse Source

Deal with the changes of the badger API

Gwyneth Llewelyn 7 years ago
parent
commit
bf56c63448
1 changed files with 11 additions and 4 deletions
  1. 11 4
      gosl.go

+ 11 - 4
gosl.go

@@ -9,7 +9,7 @@ import (
 	"flag"
 	"flag"
 	"fmt"
 	"fmt"
 	"github.com/dgraph-io/badger"
 	"github.com/dgraph-io/badger"
-	"github.com/dgraph-io/badger/table"
+	"github.com/dgraph-io/badger/options"
 	"github.com/op/go-logging"
 	"github.com/op/go-logging"
 	"gopkg.in/natefinch/lumberjack.v2"
 	"gopkg.in/natefinch/lumberjack.v2"
 	"io"
 	"io"
@@ -117,7 +117,7 @@ func main() {
 	Opt.Dir = *myDir
 	Opt.Dir = *myDir
 	Opt.ValueDir = Opt.Dir
 	Opt.ValueDir = Opt.Dir
 	if *noMemory {
 	if *noMemory {
-		Opt.MapTablesTo = table.Nothing
+		Opt.TableLoadingMode = options.FileIO // use standard file I/O operations for tables instead of LoadRAM 
 		log.Info("Trying to avoid too much memory consumption")	
 		log.Info("Trying to avoid too much memory consumption")	
 	}
 	}
 	kv, err := badger.NewKV(&Opt)
 	kv, err := badger.NewKV(&Opt)
@@ -260,7 +260,10 @@ func searchKVname(avatarName string) (UUID string, grid string) {
 		return NullUUID, ""
 		return NullUUID, ""
 	}
 	}
 	var val avatarUUID
 	var val avatarUUID
-	if err = json.Unmarshal(item.Value(), &val); err != nil {
+	if err = json.Unmarshal(item.Value(func(v []byte) {
+    		value = make([]byte, len(v))
+			copy(value, v)
+		}), &val); err != nil {
 		log.Errorf("Error while unparsing UUID for name: %s - %v\n", avatarName, err)
 		log.Errorf("Error while unparsing UUID for name: %s - %v\n", avatarName, err)
 		return NullUUID, ""
 		return NullUUID, ""
 	}
 	}
@@ -279,7 +282,10 @@ func searchKVUUID(avatarKey string) (name string, grid string) {
 	time_start := time.Now()
 	time_start := time.Now()
 	for itr.Rewind(); itr.Valid(); itr.Next() {
 	for itr.Rewind(); itr.Valid(); itr.Next() {
 		item := itr.Item()
 		item := itr.Item()
-		if err = json.Unmarshal(item.Value(), &val); err == nil {
+		if err = json.Unmarshal(item.Value(func(v []byte) {
+				value = make([]byte, len(v))
+				copy(value, v)
+			}), &val); err == nil {
 			checks++	//Just to see how many
 			checks++	//Just to see how many
 			if avatarKey == val.UUID {	// are these pointers?
 			if avatarKey == val.UUID {	// are these pointers?
 				found = string(item.Key())
 				found = string(item.Key())
@@ -311,6 +317,7 @@ func importDatabase(filename string) {
 	checkErrPanic(err) // should probably panic		
 	checkErrPanic(err) // should probably panic		
 	defer kv.Close()
 	defer kv.Close()
 	time_start := time.Now()
 	time_start := time.Now()
+	// probably better to get several chunks and use BatchSet concurrently, as recommended per the Badger instructions
 	for {
 	for {
 		record, err := cr.Read()
 		record, err := cr.Read()
 		if err == io.EOF {
 		if err == io.EOF {