@nxtedition/rocksdb 13.4.4 → 13.5.1

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;
@@ -1120,6 +1121,8 @@ NAPI_METHOD(db_open) {
1120
1121
  NAPI_STATUS_THROWS(GetProperty(env, options, "parallelism", parallelism));
1121
1122
  dbOptions.IncreaseParallelism(parallelism);
1122
1123
 
1124
+ NAPI_STATUS_THROWS(GetProperty(env, options, "walDir", dbOptions.wal_dir));
1125
+
1123
1126
  uint32_t walTTL = 0;
1124
1127
  NAPI_STATUS_THROWS(GetProperty(env, options, "walTTL", walTTL));
1125
1128
  dbOptions.WAL_ttl_seconds = walTTL / 1e3;
@@ -1725,6 +1728,20 @@ NAPI_METHOD(batch_put) {
1725
1728
  return 0;
1726
1729
  }
1727
1730
 
1731
+ NAPI_METHOD(batch_put_log_data) {
1732
+ NAPI_ARGV(3);
1733
+
1734
+ rocksdb::WriteBatch* batch;
1735
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&batch)));
1736
+
1737
+ rocksdb::Slice blob;
1738
+ NAPI_STATUS_THROWS(GetValue(env, argv[1], blob));
1739
+
1740
+ ROCKS_STATUS_THROWS_NAPI(batch->PutLogData(blob));
1741
+
1742
+ return 0;
1743
+ }
1744
+
1728
1745
  NAPI_METHOD(batch_del) {
1729
1746
  NAPI_ARGV(3);
1730
1747
 
@@ -1853,6 +1870,142 @@ NAPI_METHOD(batch_iterate) {
1853
1870
  return result;
1854
1871
  }
1855
1872
 
1873
+ struct Updates : public BatchIterator, public Closable {
1874
+ Updates(Database* database,
1875
+ const int64_t since,
1876
+ const bool keys,
1877
+ const bool values,
1878
+ const bool data,
1879
+ const rocksdb::ColumnFamilyHandle* column,
1880
+ const Encoding keyEncoding,
1881
+ const Encoding valueEncoding)
1882
+ : BatchIterator(database, keys, values, data, column, keyEncoding, valueEncoding),
1883
+ database_(database),
1884
+ start_(since) {
1885
+ database_->Attach(this);
1886
+ }
1887
+
1888
+ virtual ~Updates() {
1889
+ if (iterator_) {
1890
+ database_->Detach(this);
1891
+ }
1892
+ }
1893
+
1894
+ rocksdb::Status Close() override {
1895
+ if (iterator_) {
1896
+ iterator_.reset();
1897
+ database_->Detach(this);
1898
+ }
1899
+ return rocksdb::Status::OK();
1900
+ }
1901
+
1902
+ Database* database_;
1903
+ int64_t start_;
1904
+ std::unique_ptr<rocksdb::TransactionLogIterator> iterator_;
1905
+
1906
+ private:
1907
+ napi_ref ref_ = nullptr;
1908
+ };
1909
+
1910
+ NAPI_METHOD(updates_init) {
1911
+ NAPI_ARGV(2);
1912
+
1913
+ try {
1914
+ Database* database;
1915
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1916
+
1917
+ const auto options = argv[1];
1918
+
1919
+ int64_t since = 0;
1920
+ NAPI_STATUS_THROWS(GetProperty(env, options, "since", since));
1921
+
1922
+ bool keys = true;
1923
+ NAPI_STATUS_THROWS(GetProperty(env, options, "keys", keys));
1924
+
1925
+ bool values = true;
1926
+ NAPI_STATUS_THROWS(GetProperty(env, options, "values", values));
1927
+
1928
+ bool data = true;
1929
+ NAPI_STATUS_THROWS(GetProperty(env, options, "data", data));
1930
+
1931
+ Encoding keyEncoding = Encoding::String;
1932
+ NAPI_STATUS_THROWS(GetProperty(env, options, "keyEncoding", keyEncoding));
1933
+
1934
+ Encoding valueEncoding = Encoding::String;
1935
+ NAPI_STATUS_THROWS(GetProperty(env, options, "valueEncoding", valueEncoding));
1936
+
1937
+ rocksdb::ColumnFamilyHandle* column = nullptr;
1938
+ NAPI_STATUS_THROWS(GetProperty(env, options, "column", column));
1939
+
1940
+ napi_value result;
1941
+ auto updates =
1942
+ std::unique_ptr<Updates>(new Updates(database, since, keys, values, data, column, keyEncoding, valueEncoding));
1943
+
1944
+ NAPI_STATUS_THROWS(napi_create_external(env, updates.get(), Finalize<Updates>, updates.get(), &result));
1945
+ updates.release();
1946
+
1947
+ return result;
1948
+ } catch (const std::exception& e) {
1949
+ napi_throw_error(env, nullptr, e.what());
1950
+ return nullptr;
1951
+ }
1952
+ }
1953
+
1954
+ NAPI_METHOD(updates_next) {
1955
+ NAPI_ARGV(2);
1956
+
1957
+ try {
1958
+ Updates* updates;
1959
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&updates)));
1960
+
1961
+ if (!updates->iterator_) {
1962
+ rocksdb::TransactionLogIterator::ReadOptions options;
1963
+ ROCKS_STATUS_THROWS_NAPI(updates->database_->db->GetUpdatesSince(updates->start_, &updates->iterator_, options));
1964
+ }
1965
+
1966
+ ROCKS_STATUS_THROWS_NAPI(updates->iterator_->status());
1967
+
1968
+ if (!updates->iterator_->Valid()) {
1969
+ return 0;
1970
+ }
1971
+
1972
+ auto batchResult = updates->iterator_->GetBatch();
1973
+
1974
+ napi_value rows;
1975
+ napi_value sequence;
1976
+
1977
+ NAPI_STATUS_THROWS(updates->Iterate(env, *batchResult.writeBatchPtr, &rows));
1978
+ NAPI_STATUS_THROWS(napi_create_int64(env, batchResult.sequence, &sequence));
1979
+
1980
+ ROCKS_STATUS_THROWS_NAPI(updates->iterator_->status());
1981
+ updates->iterator_->Next();
1982
+
1983
+ napi_value ret;
1984
+ NAPI_STATUS_THROWS(napi_create_object(env, &ret));
1985
+ NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "rows", rows));
1986
+ NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "seq", sequence));
1987
+ return ret;
1988
+ } catch (const std::exception& e) {
1989
+ napi_throw_error(env, nullptr, e.what());
1990
+ return nullptr;
1991
+ }
1992
+ }
1993
+
1994
+ NAPI_METHOD(updates_close) {
1995
+ NAPI_ARGV(1);
1996
+
1997
+ try {
1998
+ Updates* updates;
1999
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&updates)));
2000
+
2001
+ ROCKS_STATUS_THROWS_NAPI(updates->Close());
2002
+ return 0;
2003
+ } catch (const std::exception& e) {
2004
+ napi_throw_error(env, nullptr, e.what());
2005
+ return nullptr;
2006
+ }
2007
+ }
2008
+
1856
2009
  NAPI_INIT() {
1857
2010
  NAPI_EXPORT_FUNCTION(db_init);
1858
2011
  NAPI_EXPORT_FUNCTION(db_open);
@@ -1873,8 +2026,13 @@ NAPI_INIT() {
1873
2026
  NAPI_EXPORT_FUNCTION(iterator_nextv);
1874
2027
  NAPI_EXPORT_FUNCTION(iterator_nextv_sync);
1875
2028
 
2029
+ NAPI_EXPORT_FUNCTION(updates_init);
2030
+ NAPI_EXPORT_FUNCTION(updates_close);
2031
+ NAPI_EXPORT_FUNCTION(updates_next);
2032
+
1876
2033
  NAPI_EXPORT_FUNCTION(batch_init);
1877
2034
  NAPI_EXPORT_FUNCTION(batch_put);
2035
+ NAPI_EXPORT_FUNCTION(batch_put_log_data);
1878
2036
  NAPI_EXPORT_FUNCTION(batch_del);
1879
2037
  NAPI_EXPORT_FUNCTION(batch_clear);
1880
2038
  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.4",
3
+ "version": "13.5.1",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",