@nxtedition/rocksdb 13.4.3 → 13.5.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/binding.cc CHANGED
@@ -38,6 +38,7 @@ class NullLogger : public rocksdb::Logger {
38
38
 
39
39
  struct Database;
40
40
  class Iterator;
41
+ class Updates;
41
42
 
42
43
  struct ColumnFamily {
43
44
  rocksdb::ColumnFamilyHandle* handle;
@@ -934,9 +935,9 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
934
935
  cache = nullptr;
935
936
  } else if (compressedRatio > 0.0) {
936
937
  rocksdb::TieredCacheOptions options;
938
+ options.cache_type = rocksdb::PrimaryCacheType::kCacheTypeHCC;
937
939
  options.total_capacity = cacheSize;
938
940
  options.compressed_secondary_ratio = compressedRatio;
939
- options.comp_cache_opts.compression_type = rocksdb::CompressionType::kZSTD;
940
941
  cache = rocksdb::NewTieredCache(options);
941
942
  } else {
942
943
  cache = rocksdb::HyperClockCacheOptions(cacheSize, 0).MakeSharedCache();
@@ -962,9 +963,9 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
962
963
  }
963
964
  } else if (compressedRatio > 0.0) {
964
965
  rocksdb::TieredCacheOptions options;
966
+ options.cache_type = rocksdb::PrimaryCacheType::kCacheTypeHCC;
965
967
  options.total_capacity = cacheSize;
966
968
  options.compressed_secondary_ratio = compressedRatio;
967
- options.comp_cache_opts.compression_type = rocksdb::CompressionType::kZSTD;
968
969
  tableOptions.block_cache = rocksdb::NewTieredCache(options);
969
970
  } else {
970
971
  tableOptions.block_cache = rocksdb::HyperClockCacheOptions(cacheSize, 0).MakeSharedCache();
@@ -1725,6 +1726,20 @@ NAPI_METHOD(batch_put) {
1725
1726
  return 0;
1726
1727
  }
1727
1728
 
1729
+ NAPI_METHOD(batch_put_log_data) {
1730
+ NAPI_ARGV(3);
1731
+
1732
+ rocksdb::WriteBatch* batch;
1733
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&batch)));
1734
+
1735
+ rocksdb::Slice blob;
1736
+ NAPI_STATUS_THROWS(GetValue(env, argv[1], blob));
1737
+
1738
+ ROCKS_STATUS_THROWS_NAPI(batch->PutLogData(blob));
1739
+
1740
+ return 0;
1741
+ }
1742
+
1728
1743
  NAPI_METHOD(batch_del) {
1729
1744
  NAPI_ARGV(3);
1730
1745
 
@@ -1853,6 +1868,142 @@ NAPI_METHOD(batch_iterate) {
1853
1868
  return result;
1854
1869
  }
1855
1870
 
1871
+ struct Updates : public BatchIterator, public Closable {
1872
+ Updates(Database* database,
1873
+ const int64_t since,
1874
+ const bool keys,
1875
+ const bool values,
1876
+ const bool data,
1877
+ const rocksdb::ColumnFamilyHandle* column,
1878
+ const Encoding keyEncoding,
1879
+ const Encoding valueEncoding)
1880
+ : BatchIterator(database, keys, values, data, column, keyEncoding, valueEncoding),
1881
+ database_(database),
1882
+ start_(since) {
1883
+ database_->Attach(this);
1884
+ }
1885
+
1886
+ virtual ~Updates() {
1887
+ if (iterator_) {
1888
+ database_->Detach(this);
1889
+ }
1890
+ }
1891
+
1892
+ rocksdb::Status Close() override {
1893
+ if (iterator_) {
1894
+ iterator_.reset();
1895
+ database_->Detach(this);
1896
+ }
1897
+ return rocksdb::Status::OK();
1898
+ }
1899
+
1900
+ Database* database_;
1901
+ int64_t start_;
1902
+ std::unique_ptr<rocksdb::TransactionLogIterator> iterator_;
1903
+
1904
+ private:
1905
+ napi_ref ref_ = nullptr;
1906
+ };
1907
+
1908
+ NAPI_METHOD(updates_init) {
1909
+ NAPI_ARGV(2);
1910
+
1911
+ try {
1912
+ Database* database;
1913
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1914
+
1915
+ const auto options = argv[1];
1916
+
1917
+ int64_t since = 0;
1918
+ NAPI_STATUS_THROWS(GetProperty(env, options, "since", since));
1919
+
1920
+ bool keys = true;
1921
+ NAPI_STATUS_THROWS(GetProperty(env, options, "keys", keys));
1922
+
1923
+ bool values = true;
1924
+ NAPI_STATUS_THROWS(GetProperty(env, options, "values", values));
1925
+
1926
+ bool data = true;
1927
+ NAPI_STATUS_THROWS(GetProperty(env, options, "data", data));
1928
+
1929
+ Encoding keyEncoding = Encoding::String;
1930
+ NAPI_STATUS_THROWS(GetProperty(env, options, "keyEncoding", keyEncoding));
1931
+
1932
+ Encoding valueEncoding = Encoding::String;
1933
+ NAPI_STATUS_THROWS(GetProperty(env, options, "valueEncoding", valueEncoding));
1934
+
1935
+ rocksdb::ColumnFamilyHandle* column = nullptr;
1936
+ NAPI_STATUS_THROWS(GetProperty(env, options, "column", column));
1937
+
1938
+ napi_value result;
1939
+ auto updates =
1940
+ std::unique_ptr<Updates>(new Updates(database, since, keys, values, data, column, keyEncoding, valueEncoding));
1941
+
1942
+ NAPI_STATUS_THROWS(napi_create_external(env, updates.get(), Finalize<Updates>, updates.get(), &result));
1943
+ updates.release();
1944
+
1945
+ return result;
1946
+ } catch (const std::exception& e) {
1947
+ napi_throw_error(env, nullptr, e.what());
1948
+ return nullptr;
1949
+ }
1950
+ }
1951
+
1952
+ NAPI_METHOD(updates_next) {
1953
+ NAPI_ARGV(2);
1954
+
1955
+ try {
1956
+ Updates* updates;
1957
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&updates)));
1958
+
1959
+ if (!updates->iterator_) {
1960
+ rocksdb::TransactionLogIterator::ReadOptions options;
1961
+ ROCKS_STATUS_THROWS_NAPI(updates->database_->db->GetUpdatesSince(updates->start_, &updates->iterator_, options));
1962
+ }
1963
+
1964
+ ROCKS_STATUS_THROWS_NAPI(updates->iterator_->status());
1965
+
1966
+ if (!updates->iterator_->Valid()) {
1967
+ return 0;
1968
+ }
1969
+
1970
+ auto batchResult = updates->iterator_->GetBatch();
1971
+
1972
+ napi_value rows;
1973
+ napi_value sequence;
1974
+
1975
+ NAPI_STATUS_THROWS(updates->Iterate(env, *batchResult.writeBatchPtr, &rows));
1976
+ NAPI_STATUS_THROWS(napi_create_int64(env, batchResult.sequence, &sequence));
1977
+
1978
+ ROCKS_STATUS_THROWS_NAPI(updates->iterator_->status());
1979
+ updates->iterator_->Next();
1980
+
1981
+ napi_value ret;
1982
+ NAPI_STATUS_THROWS(napi_create_object(env, &ret));
1983
+ NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "rows", rows));
1984
+ NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "seq", sequence));
1985
+ return ret;
1986
+ } catch (const std::exception& e) {
1987
+ napi_throw_error(env, nullptr, e.what());
1988
+ return nullptr;
1989
+ }
1990
+ }
1991
+
1992
+ NAPI_METHOD(updates_close) {
1993
+ NAPI_ARGV(1);
1994
+
1995
+ try {
1996
+ Updates* updates;
1997
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&updates)));
1998
+
1999
+ ROCKS_STATUS_THROWS_NAPI(updates->Close());
2000
+ return 0;
2001
+ } catch (const std::exception& e) {
2002
+ napi_throw_error(env, nullptr, e.what());
2003
+ return nullptr;
2004
+ }
2005
+ }
2006
+
1856
2007
  NAPI_INIT() {
1857
2008
  NAPI_EXPORT_FUNCTION(db_init);
1858
2009
  NAPI_EXPORT_FUNCTION(db_open);
@@ -1873,8 +2024,13 @@ NAPI_INIT() {
1873
2024
  NAPI_EXPORT_FUNCTION(iterator_nextv);
1874
2025
  NAPI_EXPORT_FUNCTION(iterator_nextv_sync);
1875
2026
 
2027
+ NAPI_EXPORT_FUNCTION(updates_init);
2028
+ NAPI_EXPORT_FUNCTION(updates_close);
2029
+ NAPI_EXPORT_FUNCTION(updates_next);
2030
+
1876
2031
  NAPI_EXPORT_FUNCTION(batch_init);
1877
2032
  NAPI_EXPORT_FUNCTION(batch_put);
2033
+ NAPI_EXPORT_FUNCTION(batch_put_log_data);
1878
2034
  NAPI_EXPORT_FUNCTION(batch_del);
1879
2035
  NAPI_EXPORT_FUNCTION(batch_clear);
1880
2036
  NAPI_EXPORT_FUNCTION(batch_write);
package/chained-batch.js CHANGED
@@ -41,6 +41,20 @@ class ChainedBatch extends AbstractChainedBatch {
41
41
  binding.batch_put(this[kBatchContext], key, value, options ?? EMPTY)
42
42
  }
43
43
 
44
+ _putLogData (blob) {
45
+ assert(this[kBatchContext])
46
+
47
+ if (blob === null || blob === undefined) {
48
+ throw new ModuleError('Blob cannot be null or undefined', {
49
+ code: 'LEVEL_INVALID_KEY'
50
+ })
51
+ }
52
+
53
+ blob = typeof blob === 'string' ? Buffer.from(blob) : blob
54
+
55
+ binding.batch_put_log_data(this[kBatchContext], blob)
56
+ }
57
+
44
58
  _del (key, options) {
45
59
  assert(this[kBatchContext])
46
60
 
package/index.js CHANGED
@@ -269,6 +269,21 @@ class RocksLevel extends AbstractLevel {
269
269
 
270
270
  return binding.db_query(this[kContext], options ?? kEmpty)
271
271
  }
272
+
273
+ async * updates (options) {
274
+ const handle = binding.updates_init(this[kContext], options)
275
+ try {
276
+ while (true) {
277
+ const value = binding.updates_next(handle)
278
+ if (!value) {
279
+ break
280
+ }
281
+ yield value
282
+ }
283
+ } finally {
284
+ binding.updates_close(handle)
285
+ }
286
+ }
272
287
  }
273
288
 
274
289
  exports.RocksLevel = RocksLevel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "13.4.3",
3
+ "version": "13.5.0",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",