1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
foreach(variable SERVER WRITE_INPUT HEALTH_INPUT DATA_DIR)
if(NOT DEFINED ${variable})
message(FATAL_ERROR "${variable} is required")
endif()
endforeach()
file(REMOVE_RECURSE "${DATA_DIR}")
execute_process(
COMMAND "${SERVER}" --data-dir "${DATA_DIR}"
INPUT_FILE "${WRITE_INPUT}"
OUTPUT_VARIABLE write_output
ERROR_VARIABLE write_error
RESULT_VARIABLE write_result
)
if(NOT write_result EQUAL 0)
message(FATAL_ERROR "initial write failed: ${write_error}")
endif()
string(REGEX MATCH "message_id[^0-9A-Z]+([0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z])" match "${write_output}")
set(message_id "${CMAKE_MATCH_1}")
if(NOT message_id)
message(FATAL_ERROR "could not extract message ID from: ${write_output}")
endif()
set(delete_input "${DATA_DIR}/delete.jsonl")
file(WRITE "${delete_input}"
"{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2024-11-05\",\"capabilities\":{},\"clientInfo\":{\"name\":\"lifecycle\",\"version\":\"1\"}}}\n"
"{\"jsonrpc\":\"2.0\",\"method\":\"notifications/initialized\",\"params\":{}}\n"
"{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/call\",\"params\":{\"name\":\"delete_message\",\"arguments\":{\"message_id\":\"${message_id}\",\"session_id\":\"lifecycle\"}}}\n"
"{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"read_messages\",\"arguments\":{\"session_id\":\"lifecycle\"}}}\n"
"{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"tools/call\",\"params\":{\"name\":\"rebuild_index\",\"arguments\":{}}}\n"
)
execute_process(COMMAND "${SERVER}" --data-dir "${DATA_DIR}" INPUT_FILE "${delete_input}"
OUTPUT_VARIABLE delete_output ERROR_VARIABLE delete_error RESULT_VARIABLE delete_result)
if(NOT delete_result EQUAL 0 OR NOT delete_output MATCHES "records_removed[^0-9]+1")
message(FATAL_ERROR "delete/compaction failed: ${delete_output} ${delete_error}")
endif()
file(READ "${DATA_DIR}/active.log" compacted_hex HEX)
string(FIND "${compacted_hex}" "7365637265742d746f2d72656d6f7665" secret_position)
if(NOT secret_position EQUAL -1)
message(FATAL_ERROR "compacted log still contains deleted content")
endif()
file(APPEND "${DATA_DIR}/active.log" "TC")
file(WRITE "${DATA_DIR}/snapshot.bin" "invalid snapshot")
execute_process(COMMAND "${SERVER}" --data-dir "${DATA_DIR}" INPUT_FILE "${HEALTH_INPUT}"
OUTPUT_VARIABLE recovery_output ERROR_VARIABLE recovery_error RESULT_VARIABLE recovery_result)
string(FIND "${recovery_output}" "secret-to-remove" recovered_secret_position)
if(NOT recovery_result EQUAL 0 OR NOT recovery_output MATCHES "recovered_tail[^a-z]+true" OR
NOT recovery_output MATCHES "snapshot_valid[^a-z]+false" OR NOT recovered_secret_position EQUAL -1)
message(FATAL_ERROR "restart/tail recovery failed: ${recovery_output} ${recovery_error}")
endif()
|