@@ -36,6 +36,10 @@ ${MEMLIMIT0} SEPARATOR=\n
3636Etcd Database Defragment Manually
3737 [Documentation] Verify that etcd database can be manually defragmented
3838 ... using etcdctl and the database size does not grow.
39+ ... Creates artificial fragmentation first to ensure defrag has
40+ ... meaningful work to do regardless of the initial DB state
41+ ... (e.g. after etcd storage version migration).
42+ Create Etcd Fragmentation
3943 ${size_before } = Get Etcd Database Size
4044 Command Should Work ${ETCDCTL_CMD } defrag
4145 ${size_after } = Get Etcd Database Size
@@ -138,6 +142,22 @@ Install Etcdctl
138142 ... The binary is pre-downloaded with checksum verification by scripts/fetch_tools.sh.
139143 Put File ${ETCDCTL_LOCAL_PATH } ${ETCDCTL_BIN }
140144
145+ Create Etcd Fragmentation
146+ [Documentation] Create artificial fragmentation in the etcd database by
147+ ... writing and then deleting a set of keys. The deleted keys leave
148+ ... dead space that defrag can reclaim, ensuring the defrag test
149+ ... works even when the DB starts fully compacted.
150+ FOR ${i } IN RANGE 100
151+ Command Should Work ${ETCDCTL_CMD } put /defrag-test/key-${i } "$(head -c 1024 /dev/urandom | base64 -w0)"
152+ END
153+ FOR ${i } IN RANGE 100
154+ Command Should Work ${ETCDCTL_CMD } del /defrag-test/key-${i }
155+ END
156+ ${output } = Command Should Work ${ETCDCTL_CMD } endpoint status --write-out\=json
157+ ${revision } = Command Should Work
158+ ... printf '%s' '${output } ' | python3 -c "import sys,json; print(json.load(sys.stdin)[0]['Status']['header']['revision'])"
159+ Command Should Work ${ETCDCTL_CMD } compact ${revision }
160+
141161Get Etcd Database Size
142162 [Documentation] Return the current etcd database size in bytes
143163 ${output } = Command Should Work ${ETCDCTL_CMD } endpoint status --write-out\=json
0 commit comments