Skip to content

Commit 7198128

Browse files
committed
Merge branch 'openriak-4.0' of https://github.com/OpenRiak/leveled into openriak-4.0
2 parents 1b9b445 + 6be86b6 commit 7198128

2 files changed

Lines changed: 71 additions & 22 deletions

File tree

src/leveled_cdb.erl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,12 @@ rolling(
724724
},
725725
case State#state.deferred_delete of
726726
true ->
727-
{next_state, delete_pending, State0, [{reply, From, ok}]};
727+
{
728+
next_state,
729+
delete_pending,
730+
State0,
731+
[{reply, From, ok}, ?DELETE_TIMEOUT]
732+
};
728733
false ->
729734
?TMR_LOG(cdb18, [], SW),
730735
{next_state, reader, State0, [{reply, From, ok}, hibernate]}
@@ -3091,6 +3096,35 @@ pendingdelete_test() ->
30913096
% No issues destroying even though the file has already been removed
30923097
ok = cdb_destroy(P2).
30933098

3099+
deletewhenrolling_test_() ->
3100+
{timeout, 60000, fun deletewhenrolling_tester/0}.
3101+
3102+
deletewhenrolling_tester() ->
3103+
F1 = "test/test_area/deleterolling_test.pnd",
3104+
file:delete(F1),
3105+
{ok, P1} = cdb_open_writer(F1, #cdb_options{binary_mode = false}),
3106+
KVList = generate_sequentialkeys(5000, []),
3107+
ok = cdb_mput(P1, KVList),
3108+
ok = cdb_roll(P1),
3109+
SpawnFakeInker = spawn(fun() -> ok end),
3110+
ok = cdb_deletepending(P1, 5000, SpawnFakeInker),
3111+
?assertMatch({"Key1", "Value1"}, cdb_get(P1, "Key1")),
3112+
?assertMatch({"Key1000", "Value1000"}, cdb_get(P1, "Key1000")),
3113+
?assertMatch({"Key4000", "Value4000"}, cdb_get(P1, "Key4000")),
3114+
timer:sleep(?DELETE_TIMEOUT - 1000),
3115+
lists:foreach(
3116+
fun(_I) ->
3117+
case is_process_alive(P1) of
3118+
true ->
3119+
timer:sleep(1000);
3120+
false ->
3121+
ok
3122+
end
3123+
end,
3124+
lists:seq(1, 10)
3125+
),
3126+
?assertMatch(false, is_process_alive(P1)).
3127+
30943128
getpositions_sample_test() ->
30953129
% what if we try and get positions with a file with o(1000) entries
30963130
F1 = "test/test_area/getpos_sample_test.pnd",

src/leveled_inker.erl

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,18 +1576,33 @@ build_dummy_journal(KeyConvertF) ->
15761576
ok = filelib:ensure_dir(ManifestFP),
15771577
F1 = filename:join(JournalFP, "nursery_1.pnd"),
15781578
{ok, J1} = leveled_cdb:cdb_open_writer(F1),
1579+
%% Load some dummmy keys to avoid timing issues when scenarios are not
1580+
%% triggered due to hashtable being calculated too fast
1581+
lists:foreach(
1582+
fun(I) ->
1583+
DK = lists:flatten(io_lib:format("DummmyK~6..0w", [I])),
1584+
DV = lists:flatten(io_lib:format("TestValue~6..0w", [I])),
1585+
leveled_cdb:cdb_put(
1586+
J1,
1587+
{I, stnd, KeyConvertF(DK)},
1588+
create_value_for_journal({DV, ?TEST_KC}, false)
1589+
)
1590+
end,
1591+
lists:seq(1, 1000)
1592+
),
1593+
15791594
{K1, V1} = {KeyConvertF("Key1"), "TestValue1"},
15801595
{K2, V2} = {KeyConvertF("Key2"), "TestValue2"},
15811596
ok =
15821597
leveled_cdb:cdb_put(
15831598
J1,
1584-
{1, stnd, K1},
1599+
{1001, stnd, K1},
15851600
create_value_for_journal({V1, ?TEST_KC}, false)
15861601
),
15871602
ok =
15881603
leveled_cdb:cdb_put(
15891604
J1,
1590-
{2, stnd, K2},
1605+
{1002, stnd, K2},
15911606
create_value_for_journal({V2, ?TEST_KC}, false)
15921607
),
15931608
ok = leveled_cdb:cdb_roll(J1),
@@ -1618,20 +1633,20 @@ build_dummy_journal(KeyConvertF) ->
16181633
ok =
16191634
leveled_cdb:cdb_put(
16201635
J2,
1621-
{3, stnd, K1},
1636+
{1003, stnd, K1},
16221637
create_value_for_journal({V3, ?TEST_KC}, false)
16231638
),
16241639
ok =
16251640
leveled_cdb:cdb_put(
16261641
J2,
1627-
{4, stnd, K4},
1642+
{1004, stnd, K4},
16281643
create_value_for_journal({V4, ?TEST_KC}, false)
16291644
),
16301645
LK2 = leveled_cdb:cdb_lastkey(J2),
16311646
ok = leveled_cdb:cdb_close(J2),
16321647
Manifest = [
16331648
{1, "test/test_area/journal/journal_files/nursery_1", "pid1", LK1},
1634-
{3, "test/test_area/journal/journal_files/nursery_3", "pid2", LK2}
1649+
{1003, "test/test_area/journal/journal_files/nursery_3", "pid2", LK2}
16351650
],
16361651
ManifestBin = term_to_binary(Manifest),
16371652
{ok, MF1} = file:open(
@@ -1671,12 +1686,12 @@ simple_inker_test() ->
16711686
compression_method = native,
16721687
compress_on_receipt = true
16731688
}),
1674-
Obj1 = ink_get(Ink1, key_converter("Key1"), 1),
1675-
?assertMatch(Obj1, {{1, key_converter("Key1")}, {"TestValue1", ?TEST_KC}}),
1676-
Obj3 = ink_get(Ink1, key_converter("Key1"), 3),
1677-
?assertMatch(Obj3, {{3, key_converter("Key1")}, {"TestValue3", ?TEST_KC}}),
1678-
Obj4 = ink_get(Ink1, key_converter("Key4"), 4),
1679-
?assertMatch(Obj4, {{4, key_converter("Key4")}, {"TestValue4", ?TEST_KC}}),
1689+
Obj1 = ink_get(Ink1, key_converter("Key1"), 1001),
1690+
?assertMatch(Obj1, {{1001, key_converter("Key1")}, {"TestValue1", ?TEST_KC}}),
1691+
Obj3 = ink_get(Ink1, key_converter("Key1"), 1003),
1692+
?assertMatch(Obj3, {{1003, key_converter("Key1")}, {"TestValue3", ?TEST_KC}}),
1693+
Obj4 = ink_get(Ink1, key_converter("Key4"), 1004),
1694+
?assertMatch(Obj4, {{1004, key_converter("Key4")}, {"TestValue4", ?TEST_KC}}),
16801695
ink_close(Ink1),
16811696
clean_testdir(RootPath).
16821697

@@ -1697,10 +1712,10 @@ simple_inker_completeactivejournal_test() ->
16971712
compression_method = native,
16981713
compress_on_receipt = true
16991714
}),
1700-
Obj1 = ink_get(Ink1, key_converter("Key1"), 1),
1701-
?assertMatch(Obj1, {{1, key_converter("Key1")}, {"TestValue1", ?TEST_KC}}),
1702-
Obj2 = ink_get(Ink1, key_converter("Key4"), 4),
1703-
?assertMatch(Obj2, {{4, key_converter("Key4")}, {"TestValue4", ?TEST_KC}}),
1715+
Obj1 = ink_get(Ink1, key_converter("Key1"), 1001),
1716+
?assertMatch(Obj1, {{1001, key_converter("Key1")}, {"TestValue1", ?TEST_KC}}),
1717+
Obj2 = ink_get(Ink1, key_converter("Key4"), 1004),
1718+
?assertMatch(Obj2, {{1004, key_converter("Key4")}, {"TestValue4", ?TEST_KC}}),
17041719
ink_close(Ink1),
17051720
clean_testdir(RootPath).
17061721

@@ -1738,12 +1753,12 @@ compact_journal_testto(WRP, ExpectedFiles) ->
17381753
{[], infinity},
17391754
true
17401755
),
1741-
?assertMatch(NewSQN1, 5),
1756+
?assertMatch(NewSQN1, 1005),
17421757
ok = ink_printmanifest(Ink1),
1743-
R0 = ink_get(Ink1, test_ledgerkey("KeyAA"), 5),
1758+
R0 = ink_get(Ink1, test_ledgerkey("KeyAA"), 1005),
17441759
?assertMatch(
17451760
R0,
1746-
{{5, test_ledgerkey("KeyAA")}, {"TestValueAA", {[], infinity}}}
1761+
{{1005, test_ledgerkey("KeyAA")}, {"TestValueAA", {[], infinity}}}
17471762
),
17481763
FunnyLoop = lists:seq(1, 48),
17491764
Checker = lists:map(
@@ -1767,14 +1782,14 @@ compact_journal_testto(WRP, ExpectedFiles) ->
17671782
{[], infinity},
17681783
true
17691784
),
1770-
?assertMatch(NewSQN2, 54),
1785+
?assertMatch(NewSQN2, 1054),
17711786
ActualManifest = ink_getmanifest(Ink1),
17721787
ok = ink_printmanifest(Ink1),
17731788
?assertMatch(3, length(ActualManifest)),
17741789
{ok, _ICL1} = ink_compactjournal(
17751790
Ink1,
17761791
Checker,
1777-
fun(X) -> {X, 55} end,
1792+
fun(X) -> {X, 1055} end,
17781793
fun(_F) -> ok end,
17791794
fun(L, K, SQN) ->
17801795
case lists:member({SQN, K}, L) of
@@ -1791,7 +1806,7 @@ compact_journal_testto(WRP, ExpectedFiles) ->
17911806
{ok, _ICL2} = ink_compactjournal(
17921807
Ink1,
17931808
Checker2,
1794-
fun(X) -> {X, 55} end,
1809+
fun(X) -> {X, 1055} end,
17951810
fun(_F) -> ok end,
17961811
fun(L, K, SQN) ->
17971812
case lists:member({SQN, K}, L) of

0 commit comments

Comments
 (0)