Packages
rocksdb
2.6.0
3.1.1
3.1.0
3.0.0
2.6.2
2.6.1
retired
2.6.0
retired
2.5.0
2.4.1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.9.0
1.8.0
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.0
0.26.2
0.26.1
0.26.0
0.25.0
0.24.0
0.23.3
0.23.2
0.23.1
0.23.0
0.22.0
0.21.0
0.20.1
0.20.0
0.19.0
0.18.0
0.17.0
0.16.0
0.15.0
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
RocksDB for Erlang
Retired package: Release invalid - Use 2.6.1 instead
Current section
Files
Jump to
Current section
Files
test/memtable_statistics.erl
%% Copyright (c) 2025 Benoit Chesneau
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
-module(memtable_statistics).
-include_lib("eunit/include/eunit.hrl").
-define(rm_rf(Dir), rocksdb_test_util:rm_rf(Dir)).
memtable_hit_miss_test() ->
?rm_rf("test_memtable_stats"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_memtable_stats",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Write data without flush - stays in memtable
lists:foreach(
fun(I) ->
Key = <<$m, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(50, $a)),
ok = rocksdb:put(Db, Key, Value, [])
end,
lists:seq(1, 50)),
%% Read back - should hit memtable
lists:foreach(
fun(I) ->
Key = <<$m, (integer_to_binary(I))/binary>>,
{ok, _} = rocksdb:get(Db, Key, [])
end,
lists:seq(1, 50)),
%% Check memtable_hit and memtable_miss are readable
{ok, MemtableHit} = rocksdb:statistics_ticker(Stats, memtable_hit),
{ok, MemtableMiss} = rocksdb:statistics_ticker(Stats, memtable_miss),
?assert(is_integer(MemtableHit)),
?assert(is_integer(MemtableMiss)),
%% We should have memtable hits since data is in memtable
?assert(MemtableHit >= 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_memtable_stats")
end,
ok.
write_done_counters_test() ->
?rm_rf("test_write_done_stats"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_write_done_stats",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Perform some writes
lists:foreach(
fun(I) ->
Key = <<$w, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(100, $b)),
ok = rocksdb:put(Db, Key, Value, [])
end,
lists:seq(1, 100)),
%% Check write_done counters
{ok, WriteBySelf} = rocksdb:statistics_ticker(Stats, write_done_by_self),
{ok, WriteByOther} = rocksdb:statistics_ticker(Stats, write_done_by_other),
?assert(is_integer(WriteBySelf)),
?assert(is_integer(WriteByOther)),
%% At least some writes should be done by self
?assert(WriteBySelf >= 0),
?assert(WriteByOther >= 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_write_done_stats")
end,
ok.
wal_sync_test() ->
?rm_rf("test_wal_sync_stats"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_wal_sync_stats",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Write with sync option to trigger WAL sync
lists:foreach(
fun(I) ->
Key = <<$s, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(50, $c)),
ok = rocksdb:put(Db, Key, Value, [{sync, true}])
end,
lists:seq(1, 10)),
%% Check wal_file_synced counter
{ok, WalSynced} = rocksdb:statistics_ticker(Stats, wal_file_synced),
?assert(is_integer(WalSynced)),
%% With sync writes, should have WAL syncs
?assert(WalSynced > 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_wal_sync_stats")
end,
ok.
stall_micros_test() ->
?rm_rf("test_stall_stats"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_stall_stats",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Just verify stall_micros is readable
{ok, StallMicros} = rocksdb:statistics_ticker(Stats, stall_micros),
?assert(is_integer(StallMicros)),
%% Stall micros should be >= 0 (likely 0 with small data)
?assert(StallMicros >= 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_stall_stats")
end,
ok.