hypercore-storage 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -524,8 +524,8 @@ class CorestoreStorage {
524
524
  return this.db.ready()
525
525
  }
526
526
 
527
- compact() {
528
- return this.db.compactRange()
527
+ compact(opts) {
528
+ return this.db.compactRange(opts)
529
529
  }
530
530
 
531
531
  async audit() {
@@ -1228,19 +1228,24 @@ function createColumnFamily(db, opts = {}) {
1228
1228
  const {
1229
1229
  tableCacheIndexAndFilterBlocks = true,
1230
1230
  blockCache = true,
1231
- optimizeFiltersForMemory = false
1231
+ optimizeFiltersForMemory = false,
1232
+ blobFileSize = 256 * 1024 * 1024,
1233
+ blobGarbageCollectionAgeCutOff = 0.25,
1234
+ blobGarbageCollectionForceThreshold = 1.0
1232
1235
  } = opts
1233
1236
 
1234
1237
  const col = new RocksDB.ColumnFamily(COLUMN_FAMILY, {
1235
1238
  enableBlobFiles: true,
1236
1239
  minBlobSize: 4096,
1237
- blobFileSize: 256 * 1024 * 1024,
1240
+ blobFileSize,
1238
1241
  enableBlobGarbageCollection: true,
1239
1242
  tableBlockSize: 8192,
1240
1243
  tableCacheIndexAndFilterBlocks,
1241
1244
  tableFormatVersion: 6,
1242
1245
  optimizeFiltersForMemory,
1243
- blockCache
1246
+ blockCache,
1247
+ blobGarbageCollectionAgeCutOff,
1248
+ blobGarbageCollectionForceThreshold
1244
1249
  })
1245
1250
 
1246
1251
  return db.columnFamily(col)
@@ -0,0 +1,43 @@
1
+ const c = require('compact-encoding')
2
+ const schema = require('../../encoding/spec/hyperschema')
3
+ const { core: coreKey } = require('../../lib/keys.js')
4
+ const View = require('../../lib/view.js')
5
+
6
+ const CORE_AUTH = schema.getEncoding('@core/auth')
7
+
8
+ const { CorestoreRX, CorestoreTX } = require('../../lib/tx.js')
9
+
10
+ async function core (core, { version, dryRun = false } = {}) {
11
+ if (dryRun) return // dryRun mode not supported atm
12
+
13
+ const rx = core.db.read({ autoDestroy: true })
14
+ const storedAuthPromise = rx.get(coreKey.auth(core.core.corePointer))
15
+
16
+ rx.tryFlush()
17
+
18
+ const storedAuth = await storedAuthPromise
19
+ if (!storedAuth) return
20
+
21
+ const auth = c.decode(CORE_AUTH, storedAuth)
22
+ await commitCoreMigration(auth, core, version)
23
+ }
24
+
25
+ module.exports = { core }
26
+
27
+ async function commitCoreMigration (auth, core, version) {
28
+ const view = new View()
29
+ const rx = new CorestoreRX(core.db, view)
30
+
31
+ const storeCorePromise = rx.getCore(auth.discoveryKey)
32
+ rx.tryFlush()
33
+
34
+ const storeCore = await storeCorePromise
35
+
36
+ storeCore.version = version
37
+
38
+ const tx = new CorestoreTX(view)
39
+ tx.putCore(auth.discoveryKey, storeCore)
40
+ tx.apply()
41
+
42
+ await View.flush(view.changes, core.db)
43
+ }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",
7
7
  "lib/*.js",
8
8
  "encoding/*",
9
- "migrations/0/*.js"
9
+ "migrations/0/*.js",
10
+ "migrations/1/*.js"
10
11
  ],
11
12
  "scripts": {
12
13
  "format": "prettier --write .",