newKeyValueFromJSONConfig returns a KeyValue implementation on top of a github.com/syndtr/goleveldb/leveldb file.
(cfg jsonconfig.Obj)
| 52 | // newKeyValueFromJSONConfig returns a KeyValue implementation on top of a |
| 53 | // github.com/syndtr/goleveldb/leveldb file. |
| 54 | func newKeyValueFromJSONConfig(cfg jsonconfig.Obj) (sorted.KeyValue, error) { |
| 55 | file := cfg.RequiredString("file") |
| 56 | if err := cfg.Validate(); err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | strictness := opt.DefaultStrict |
| 60 | if env.IsDev() { |
| 61 | // Be more strict in dev mode. |
| 62 | strictness = opt.StrictAll |
| 63 | } |
| 64 | opts := &opt.Options{ |
| 65 | // The default is 10, |
| 66 | // 8 means 2.126% or 1/47th disk check rate, |
| 67 | // 10 means 0.812% error rate (1/2^(bits/1.44)) or 1/123th disk check rate, |
| 68 | // 12 means 0.31% or 1/322th disk check rate. |
| 69 | // TODO(tgulacsi): decide which number is the best here. Till that go with the default. |
| 70 | Filter: filter.NewBloomFilter(10), |
| 71 | Strict: strictness, |
| 72 | } |
| 73 | db, err := leveldb.OpenFile(file, opts) |
| 74 | if err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | is := &kvis{ |
| 78 | db: db, |
| 79 | path: file, |
| 80 | opts: opts, |
| 81 | readOpts: &opt.ReadOptions{Strict: strictness}, |
| 82 | // On machine crash we want to reindex anyway, and |
| 83 | // fsyncs may impose great performance penalty. |
| 84 | writeOpts: &opt.WriteOptions{Sync: false}, |
| 85 | } |
| 86 | return is, nil |
| 87 | } |
| 88 | |
| 89 | type kvis struct { |
| 90 | path string |