ldb_test.py 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. #!/usr/bin/env python3
  2. # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. import glob
  4. import os
  5. import os.path
  6. import re
  7. import shutil
  8. import subprocess
  9. import tempfile
  10. import time
  11. import unittest
  12. def my_check_output(*popenargs, **kwargs):
  13. """
  14. If we had python 2.7, we should simply use subprocess.check_output.
  15. This is a stop-gap solution for python 2.6
  16. """
  17. if "stdout" in kwargs:
  18. raise ValueError("stdout argument not allowed, it will be overridden.")
  19. process = subprocess.Popen(
  20. stderr=subprocess.PIPE, stdout=subprocess.PIPE, *popenargs, **kwargs
  21. )
  22. output, unused_err = process.communicate()
  23. retcode = process.poll()
  24. if retcode:
  25. cmd = kwargs.get("args")
  26. if cmd is None:
  27. cmd = popenargs[0]
  28. raise Exception("Exit code is not 0. It is %d. Command: %s" % (retcode, cmd))
  29. return output.decode("utf-8")
  30. def run_err_null(cmd):
  31. return os.system(cmd + " 2>/dev/null ")
  32. class LDBTestCase(unittest.TestCase):
  33. def setUp(self):
  34. self.TMP_DIR = tempfile.mkdtemp(prefix="ldb_test_")
  35. self.DB_NAME = "testdb"
  36. def tearDown(self):
  37. assert (
  38. self.TMP_DIR.strip() != "/"
  39. and self.TMP_DIR.strip() != "/tmp"
  40. and self.TMP_DIR.strip() != "/tmp/"
  41. ) # Just some paranoia
  42. shutil.rmtree(self.TMP_DIR)
  43. def dbParam(self, dbName):
  44. return "--db=%s" % os.path.join(self.TMP_DIR, dbName)
  45. def assertRunOKFull(
  46. self, params, expectedOutput, unexpected=False, isPattern=False
  47. ):
  48. """
  49. All command-line params must be specified.
  50. Allows full flexibility in testing; for example: missing db param.
  51. """
  52. output = my_check_output(
  53. './ldb %s |grep -v "Created bg thread"' % params, shell=True
  54. )
  55. if not unexpected:
  56. if isPattern:
  57. self.assertNotEqual(expectedOutput.search(output.strip()), None)
  58. else:
  59. self.assertEqual(output.strip(), expectedOutput.strip())
  60. else:
  61. if isPattern:
  62. self.assertEqual(expectedOutput.search(output.strip()), None)
  63. else:
  64. self.assertNotEqual(output.strip(), expectedOutput.strip())
  65. def assertRunFAILFull(self, params):
  66. """
  67. All command-line params must be specified.
  68. Allows full flexibility in testing; for example: missing db param.
  69. """
  70. try:
  71. my_check_output(
  72. './ldb %s >/dev/null 2>&1 |grep -v "Created bg \
  73. thread"'
  74. % params,
  75. shell=True,
  76. )
  77. except Exception:
  78. return
  79. self.fail(
  80. "Exception should have been raised for command with params: %s" % params
  81. )
  82. def assertRunOK(self, params, expectedOutput, unexpected=False):
  83. """
  84. Uses the default test db.
  85. """
  86. self.assertRunOKFull(
  87. "{} {}".format(self.dbParam(self.DB_NAME), params), expectedOutput, unexpected
  88. )
  89. def assertRunFAIL(self, params):
  90. """
  91. Uses the default test db.
  92. """
  93. self.assertRunFAILFull("{} {}".format(self.dbParam(self.DB_NAME), params))
  94. def testSimpleStringPutGet(self):
  95. print("Running testSimpleStringPutGet...")
  96. self.assertRunFAIL("put x1 y1")
  97. self.assertRunOK("put --create_if_missing x1 y1", "OK")
  98. self.assertRunOK("get x1", "y1")
  99. self.assertRunFAIL("get x2")
  100. self.assertRunOK("put x2 y2", "OK")
  101. self.assertRunOK("get x1", "y1")
  102. self.assertRunOK("get x2", "y2")
  103. self.assertRunOK("multi_get x1 x2", "x1 ==> y1\nx2 ==> y2")
  104. self.assertRunOK("get x3", "Key not found")
  105. self.assertRunOK("multi_get x3", "Key not found: x3")
  106. self.assertRunFAIL("put_entity x4")
  107. self.assertRunFAIL("put_entity x4 cv1")
  108. self.assertRunOK("put_entity x4 :cv1", "OK")
  109. self.assertRunOK("get_entity x4", ":cv1")
  110. self.assertRunOK("put_entity x5 cn1:cv1 cn2:cv2", "OK")
  111. self.assertRunOK("get_entity x5", "cn1:cv1 cn2:cv2")
  112. self.assertRunOK(
  113. "scan --from=x1 --to=z",
  114. "x1 ==> y1\nx2 ==> y2\nx4 ==> cv1\nx5 ==> cn1:cv1 cn2:cv2",
  115. )
  116. self.assertRunOK("put x3 y3", "OK")
  117. self.assertRunOK(
  118. "scan --from=x1 --to=z",
  119. "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> cv1\nx5 ==> cn1:cv1 cn2:cv2",
  120. )
  121. self.assertRunOK(
  122. "scan",
  123. "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> cv1\nx5 ==> cn1:cv1 cn2:cv2",
  124. )
  125. self.assertRunOK(
  126. "scan --from=x",
  127. "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> cv1\nx5 ==> cn1:cv1 cn2:cv2",
  128. )
  129. self.assertRunOK("scan --to=x2", "x1 ==> y1")
  130. self.assertRunOK("scan --from=x1 --to=z --max_keys=1", "x1 ==> y1")
  131. self.assertRunOK("scan --from=x1 --to=z --max_keys=2", "x1 ==> y1\nx2 ==> y2")
  132. self.assertRunOK("delete x4", "OK")
  133. self.assertRunOK("delete x5", "OK")
  134. self.assertRunOK(
  135. "scan --from=x1 --to=z --max_keys=3", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3"
  136. )
  137. self.assertRunOK(
  138. "scan --from=x1 --to=z --max_keys=4", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3"
  139. )
  140. self.assertRunOK("scan --from=x1 --to=x2", "x1 ==> y1")
  141. self.assertRunOK("scan --from=x2 --to=x4", "x2 ==> y2\nx3 ==> y3")
  142. self.assertRunFAIL("scan --from=x4 --to=z") # No results => FAIL
  143. self.assertRunFAIL("scan --from=x1 --to=z --max_keys=foo")
  144. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3")
  145. self.assertRunOK("delete x1", "OK")
  146. self.assertRunOK("scan", "x2 ==> y2\nx3 ==> y3")
  147. self.assertRunOK("delete NonExistentKey", "OK")
  148. # It is weird that GET and SCAN raise exception for
  149. # non-existent key, while delete does not
  150. self.assertRunOK("checkconsistency", "OK")
  151. def dumpDb(self, params, dumpFile):
  152. return 0 == run_err_null("./ldb dump {} > {}".format(params, dumpFile))
  153. def loadDb(self, params, dumpFile):
  154. return 0 == run_err_null("cat {} | ./ldb load {}".format(dumpFile, params))
  155. def writeExternSst(self, params, inputDumpFile, outputSst):
  156. return 0 == run_err_null(
  157. "cat {} | ./ldb write_extern_sst {} {}".format(inputDumpFile, outputSst, params)
  158. )
  159. def ingestExternSst(self, params, inputSst):
  160. return 0 == run_err_null("./ldb ingest_extern_sst {} {}".format(inputSst, params))
  161. def testStringBatchPut(self):
  162. print("Running testStringBatchPut...")
  163. self.assertRunOK("batchput x1 y1 --create_if_missing", "OK")
  164. self.assertRunOK("scan", "x1 ==> y1")
  165. self.assertRunOK('batchput x2 y2 x3 y3 "x4 abc" "y4 xyz"', "OK")
  166. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 abc ==> y4 xyz")
  167. self.assertRunFAIL("batchput")
  168. self.assertRunFAIL("batchput k1")
  169. self.assertRunFAIL("batchput k1 v1 k2")
  170. def testBlobBatchPut(self):
  171. print("Running testBlobBatchPut...")
  172. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  173. self.assertRunOK("batchput x1 y1 --create_if_missing --enable_blob_files", "OK")
  174. self.assertRunOK("scan", "x1 ==> y1")
  175. self.assertRunOK(
  176. 'batchput --enable_blob_files x2 y2 x3 y3 "x4 abc" "y4 xyz"', "OK"
  177. )
  178. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 abc ==> y4 xyz")
  179. blob_files = self.getBlobFiles(dbPath)
  180. self.assertTrue(len(blob_files) >= 1)
  181. def testBlobPut(self):
  182. print("Running testBlobPut...")
  183. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  184. self.assertRunOK("put --create_if_missing --enable_blob_files x1 y1", "OK")
  185. self.assertRunOK("get x1", "y1")
  186. self.assertRunOK("put --enable_blob_files x2 y2", "OK")
  187. self.assertRunOK("get x1", "y1")
  188. self.assertRunOK("get x2", "y2")
  189. self.assertRunFAIL("get x3")
  190. blob_files = self.getBlobFiles(dbPath)
  191. self.assertTrue(len(blob_files) >= 1)
  192. def testBlobStartingLevel(self):
  193. print("Running testBlobStartingLevel...")
  194. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  195. self.assertRunOK(
  196. "put --create_if_missing --enable_blob_files --blob_file_starting_level=10 x1 y1",
  197. "OK",
  198. )
  199. self.assertRunOK("get x1", "y1")
  200. blob_files = self.getBlobFiles(dbPath)
  201. self.assertTrue(len(blob_files) == 0)
  202. self.assertRunOK(
  203. "put --enable_blob_files --blob_file_starting_level=0 x2 y2", "OK"
  204. )
  205. self.assertRunOK("get x1", "y1")
  206. self.assertRunOK("get x2", "y2")
  207. self.assertRunFAIL("get x3")
  208. blob_files = self.getBlobFiles(dbPath)
  209. self.assertTrue(len(blob_files) >= 1)
  210. def testCountDelimDump(self):
  211. print("Running testCountDelimDump...")
  212. self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK")
  213. self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK")
  214. self.assertRunOK(
  215. "dump --count_delim",
  216. "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8",
  217. )
  218. self.assertRunOK(
  219. 'dump --count_delim="."',
  220. "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8",
  221. )
  222. self.assertRunOK("batchput x,2 x2 x,abc xabc", "OK")
  223. self.assertRunOK(
  224. 'dump --count_delim=","',
  225. "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8",
  226. )
  227. def testCountDelimIDump(self):
  228. print("Running testCountDelimIDump...")
  229. self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK")
  230. self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK")
  231. self.assertRunOK(
  232. "idump --count_delim",
  233. "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8",
  234. )
  235. self.assertRunOK(
  236. 'idump --count_delim="."',
  237. "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8",
  238. )
  239. self.assertRunOK("batchput x,2 x2 x,abc xabc", "OK")
  240. self.assertRunOK(
  241. 'idump --count_delim=","',
  242. "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8",
  243. )
  244. def testInvalidCmdLines(self):
  245. print("Running testInvalidCmdLines...")
  246. # db not specified
  247. self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing")
  248. # No param called he
  249. self.assertRunFAIL("put 0x6133 0x6233 --he --create_if_missing")
  250. # max_keys is not applicable for put
  251. self.assertRunFAIL("put 0x6133 0x6233 --max_keys=1 --create_if_missing")
  252. # hex has invalid boolean value
  253. def testHexPutGet(self):
  254. print("Running testHexPutGet...")
  255. self.assertRunOK("put a1 b1 --create_if_missing", "OK")
  256. self.assertRunOK("scan", "a1 ==> b1")
  257. self.assertRunOK("scan --hex", "0x6131 ==> 0x6231")
  258. self.assertRunFAIL("put --hex 6132 6232")
  259. self.assertRunOK("put --hex 0x6132 0x6232", "OK")
  260. self.assertRunOK("scan --hex", "0x6131 ==> 0x6231\n0x6132 ==> 0x6232")
  261. self.assertRunOK("scan", "a1 ==> b1\na2 ==> b2")
  262. self.assertRunOK("get a1", "b1")
  263. self.assertRunOK("get --hex 0x6131", "0x6231")
  264. self.assertRunOK("get a2", "b2")
  265. self.assertRunOK("get --hex 0x6132", "0x6232")
  266. self.assertRunOK("multi_get --hex 0x6131 0x6132", "0x6131 ==> 0x6231\n0x6132 ==> 0x6232")
  267. self.assertRunOK("multi_get --hex 0x6131 0xBEEF", "0x6131 ==> 0x6231\nKey not found: 0xBEEF")
  268. self.assertRunOK("get --key_hex 0x6132", "b2")
  269. self.assertRunOK("get --key_hex --value_hex 0x6132", "0x6232")
  270. self.assertRunOK("get --value_hex a2", "0x6232")
  271. self.assertRunOK(
  272. "scan --key_hex --value_hex", "0x6131 ==> 0x6231\n0x6132 ==> 0x6232"
  273. )
  274. self.assertRunOK(
  275. "scan --hex --from=0x6131 --to=0x6133",
  276. "0x6131 ==> 0x6231\n0x6132 ==> 0x6232",
  277. )
  278. self.assertRunOK("scan --hex --from=0x6131 --to=0x6132", "0x6131 ==> 0x6231")
  279. self.assertRunOK("scan --key_hex", "0x6131 ==> b1\n0x6132 ==> b2")
  280. self.assertRunOK("scan --value_hex", "a1 ==> 0x6231\na2 ==> 0x6232")
  281. self.assertRunOK("batchput --hex 0x6133 0x6233 0x6134 0x6234", "OK")
  282. self.assertRunOK("scan", "a1 ==> b1\na2 ==> b2\na3 ==> b3\na4 ==> b4")
  283. self.assertRunOK("delete --hex 0x6133", "OK")
  284. self.assertRunOK("scan", "a1 ==> b1\na2 ==> b2\na4 ==> b4")
  285. self.assertRunOK("checkconsistency", "OK")
  286. def testTtlPutGet(self):
  287. print("Running testTtlPutGet...")
  288. self.assertRunOK("put a1 b1 --ttl --create_if_missing", "OK")
  289. self.assertRunOK("scan --hex", "0x6131 ==> 0x6231", True)
  290. self.assertRunOK("dump --ttl ", "a1 ==> b1", True)
  291. self.assertRunOK("dump --hex --ttl ", "0x6131 ==> 0x6231\nKeys in range: 1")
  292. self.assertRunOK("scan --hex --ttl", "0x6131 ==> 0x6231")
  293. self.assertRunOK("get --value_hex a1", "0x6231", True)
  294. self.assertRunOK("get --ttl a1", "b1")
  295. self.assertRunOK("put a3 b3 --create_if_missing", "OK")
  296. # fails because timstamp's length is greater than value's
  297. self.assertRunFAIL("get --ttl a3")
  298. self.assertRunOK("checkconsistency", "OK")
  299. def testInvalidCmdLines(self): # noqa: F811 T25377293 Grandfathered in
  300. print("Running testInvalidCmdLines...")
  301. # db not specified
  302. self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing")
  303. # No param called he
  304. self.assertRunFAIL("put 0x6133 0x6233 --he --create_if_missing")
  305. # max_keys is not applicable for put
  306. self.assertRunFAIL("put 0x6133 0x6233 --max_keys=1 --create_if_missing")
  307. # hex has invalid boolean value
  308. self.assertRunFAIL("put 0x6133 0x6233 --hex=Boo --create_if_missing")
  309. def testDumpLoad(self):
  310. print("Running testDumpLoad...")
  311. self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4", "OK")
  312. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  313. origDbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  314. # Dump and load without any additional params specified
  315. dumpFilePath = os.path.join(self.TMP_DIR, "dump1")
  316. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump1")
  317. self.assertTrue(self.dumpDb("--db=%s" % origDbPath, dumpFilePath))
  318. self.assertTrue(
  319. self.loadDb("--db=%s --create_if_missing" % loadedDbPath, dumpFilePath)
  320. )
  321. self.assertRunOKFull(
  322. "scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4"
  323. )
  324. # Dump and load in hex
  325. dumpFilePath = os.path.join(self.TMP_DIR, "dump2")
  326. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump2")
  327. self.assertTrue(self.dumpDb("--db=%s --hex" % origDbPath, dumpFilePath))
  328. self.assertTrue(
  329. self.loadDb(
  330. "--db=%s --hex --create_if_missing" % loadedDbPath, dumpFilePath
  331. )
  332. )
  333. self.assertRunOKFull(
  334. "scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4"
  335. )
  336. # Dump only a portion of the key range
  337. dumpFilePath = os.path.join(self.TMP_DIR, "dump3")
  338. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump3")
  339. self.assertTrue(
  340. self.dumpDb("--db=%s --from=x1 --to=x3" % origDbPath, dumpFilePath)
  341. )
  342. self.assertTrue(
  343. self.loadDb("--db=%s --create_if_missing" % loadedDbPath, dumpFilePath)
  344. )
  345. self.assertRunOKFull("scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2")
  346. # Dump upto max_keys rows
  347. dumpFilePath = os.path.join(self.TMP_DIR, "dump4")
  348. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump4")
  349. self.assertTrue(self.dumpDb("--db=%s --max_keys=3" % origDbPath, dumpFilePath))
  350. self.assertTrue(
  351. self.loadDb("--db=%s --create_if_missing" % loadedDbPath, dumpFilePath)
  352. )
  353. self.assertRunOKFull(
  354. "scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3"
  355. )
  356. # Load into an existing db, create_if_missing is not specified
  357. self.assertTrue(self.dumpDb("--db=%s" % origDbPath, dumpFilePath))
  358. self.assertTrue(self.loadDb("--db=%s" % loadedDbPath, dumpFilePath))
  359. self.assertRunOKFull(
  360. "scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4"
  361. )
  362. # Dump and load with WAL disabled
  363. dumpFilePath = os.path.join(self.TMP_DIR, "dump5")
  364. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump5")
  365. self.assertTrue(self.dumpDb("--db=%s" % origDbPath, dumpFilePath))
  366. self.assertTrue(
  367. self.loadDb(
  368. "--db=%s --disable_wal --create_if_missing" % loadedDbPath, dumpFilePath
  369. )
  370. )
  371. self.assertRunOKFull(
  372. "scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4"
  373. )
  374. # Dump and load with lots of extra params specified
  375. extraParams = " ".join(
  376. [
  377. "--bloom_bits=14",
  378. "--block_size=1024",
  379. "--auto_compaction=true",
  380. "--write_buffer_size=4194304",
  381. "--file_size=2097152",
  382. ]
  383. )
  384. dumpFilePath = os.path.join(self.TMP_DIR, "dump6")
  385. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump6")
  386. self.assertTrue(
  387. self.dumpDb("--db={} {}".format(origDbPath, extraParams), dumpFilePath)
  388. )
  389. self.assertTrue(
  390. self.loadDb(
  391. "--db={} {} --create_if_missing".format(loadedDbPath, extraParams),
  392. dumpFilePath,
  393. )
  394. )
  395. self.assertRunOKFull(
  396. "scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4"
  397. )
  398. # Dump with count_only
  399. dumpFilePath = os.path.join(self.TMP_DIR, "dump7")
  400. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump7")
  401. self.assertTrue(self.dumpDb("--db=%s --count_only" % origDbPath, dumpFilePath))
  402. self.assertTrue(
  403. self.loadDb("--db=%s --create_if_missing" % loadedDbPath, dumpFilePath)
  404. )
  405. # DB should have atleast one value for scan to work
  406. self.assertRunOKFull("put --db=%s k1 v1" % loadedDbPath, "OK")
  407. self.assertRunOKFull("scan --db=%s" % loadedDbPath, "k1 ==> v1")
  408. # Dump command fails because of typo in params
  409. dumpFilePath = os.path.join(self.TMP_DIR, "dump8")
  410. self.assertFalse(
  411. self.dumpDb("--db=%s --create_if_missing" % origDbPath, dumpFilePath)
  412. )
  413. # Dump and load with BlobDB enabled
  414. blobParams = " ".join(
  415. ["--enable_blob_files", "--min_blob_size=1", "--blob_file_size=2097152"]
  416. )
  417. dumpFilePath = os.path.join(self.TMP_DIR, "dump9")
  418. loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump9")
  419. self.assertTrue(self.dumpDb("--db=%s" % (origDbPath), dumpFilePath))
  420. self.assertTrue(
  421. self.loadDb(
  422. "--db=%s %s --create_if_missing --disable_wal"
  423. % (loadedDbPath, blobParams),
  424. dumpFilePath,
  425. )
  426. )
  427. self.assertRunOKFull(
  428. "scan --db=%s" % loadedDbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4"
  429. )
  430. blob_files = self.getBlobFiles(loadedDbPath)
  431. self.assertTrue(len(blob_files) >= 1)
  432. def testIDumpBasics(self):
  433. print("Running testIDumpBasics...")
  434. self.assertRunOK("put a val --create_if_missing", "OK")
  435. self.assertRunOK("put b val", "OK")
  436. self.assertRunOK(
  437. "idump",
  438. "'a' seq:1, type:1 => val\n"
  439. "'b' seq:2, type:1 => val\nInternal keys in range: 2",
  440. )
  441. self.assertRunOK(
  442. "idump --input_key_hex --from={} --to={}".format(hex(ord("a")), hex(ord("b"))),
  443. "'a' seq:1, type:1 => val\nInternal keys in range: 1",
  444. )
  445. def testIDumpDecodeBlobIndex(self):
  446. print("Running testIDumpDecodeBlobIndex...")
  447. self.assertRunOK("put a val --create_if_missing", "OK")
  448. self.assertRunOK("put b val --enable_blob_files", "OK")
  449. # Pattern to expect from dump with decode_blob_index flag enabled.
  450. regex = r".*\[blob ref\].*"
  451. expected_pattern = re.compile(regex)
  452. cmd = "idump %s --decode_blob_index"
  453. self.assertRunOKFull(
  454. (cmd) % (self.dbParam(self.DB_NAME)),
  455. expected_pattern,
  456. unexpected=False,
  457. isPattern=True,
  458. )
  459. def testMiscAdminTask(self):
  460. print("Running testMiscAdminTask...")
  461. # These tests need to be improved; for example with asserts about
  462. # whether compaction or level reduction actually took place.
  463. self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4", "OK")
  464. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  465. origDbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  466. self.assertTrue(0 == run_err_null("./ldb compact --db=%s" % origDbPath))
  467. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  468. self.assertTrue(
  469. 0 == run_err_null("./ldb reduce_levels --db=%s --new_levels=2" % origDbPath)
  470. )
  471. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  472. self.assertTrue(
  473. 0 == run_err_null("./ldb reduce_levels --db=%s --new_levels=3" % origDbPath)
  474. )
  475. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  476. self.assertTrue(
  477. 0 == run_err_null("./ldb compact --db=%s --from=x1 --to=x3" % origDbPath)
  478. )
  479. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  480. self.assertTrue(
  481. 0
  482. == run_err_null(
  483. "./ldb compact --db=%s --hex --from=0x6131 --to=0x6134" % origDbPath
  484. )
  485. )
  486. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  487. # TODO(dilip): Not sure what should be passed to WAL.Currently corrupted.
  488. self.assertTrue(
  489. 0
  490. == run_err_null(
  491. "./ldb dump_wal --db=%s --walfile=%s --header"
  492. % (origDbPath, origDbPath)
  493. )
  494. )
  495. self.assertRunOK("scan", "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4")
  496. def testCheckConsistency(self):
  497. print("Running testCheckConsistency...")
  498. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  499. self.assertRunOK("put x1 y1 --create_if_missing", "OK")
  500. self.assertRunOK("put x2 y2", "OK")
  501. self.assertRunOK("get x1", "y1")
  502. self.assertRunOK("checkconsistency", "OK")
  503. sstFilePath = my_check_output(
  504. "ls %s" % os.path.join(dbPath, "*.sst"), shell=True
  505. )
  506. # Modify the file
  507. my_check_output("echo 'evil' > %s" % sstFilePath, shell=True)
  508. self.assertRunFAIL("checkconsistency")
  509. # Delete the file
  510. my_check_output("rm -f %s" % sstFilePath, shell=True)
  511. self.assertRunFAIL("checkconsistency")
  512. def dumpLiveFiles(self, params, dumpFile):
  513. return 0 == run_err_null("./ldb dump_live_files {} > {}".format(params, dumpFile))
  514. def testDumpLiveFiles(self):
  515. print("Running testDumpLiveFiles...")
  516. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  517. self.assertRunOK("put x1 y1 --create_if_missing", "OK")
  518. self.assertRunOK("put x2 y2 --enable_blob_files", "OK")
  519. dumpFilePath = os.path.join(self.TMP_DIR, "dump1")
  520. self.assertTrue(self.dumpLiveFiles("--db=%s" % dbPath, dumpFilePath))
  521. self.assertRunOK("delete x1", "OK")
  522. self.assertRunOK("put x3 y3", "OK")
  523. dumpFilePath = os.path.join(self.TMP_DIR, "dump2")
  524. # Test that if the user provides a db path that ends with
  525. # a slash '/', there is no double (or more!) slashes in the
  526. # SST and manifest file names.
  527. # Add a '/' at the end of dbPath (which normally shouldnt contain any)
  528. if dbPath[-1] != "/":
  529. dbPath += "/"
  530. # Call the dump_live_files function with the edited dbPath name.
  531. self.assertTrue(
  532. self.dumpLiveFiles(
  533. "--db=%s --decode_blob_index --dump_uncompressed_blobs" % dbPath,
  534. dumpFilePath,
  535. )
  536. )
  537. # Investigate the output
  538. with open(dumpFilePath) as tmp:
  539. data = tmp.read()
  540. # Check that all the SST filenames have a correct full path (no multiple '/').
  541. sstFileList = re.findall(r"%s.*\d+.sst" % dbPath, data)
  542. self.assertTrue(len(sstFileList) >= 1)
  543. for sstFilename in sstFileList:
  544. filenumber = re.findall(r"\d+.sst", sstFilename)[0]
  545. self.assertEqual(sstFilename, dbPath + filenumber)
  546. # Check that all the Blob filenames have a correct full path (no multiple '/').
  547. blobFileList = re.findall(r"%s.*\d+.blob" % dbPath, data)
  548. self.assertTrue(len(blobFileList) >= 1)
  549. for blobFilename in blobFileList:
  550. filenumber = re.findall(r"\d+.blob", blobFilename)[0]
  551. self.assertEqual(blobFilename, dbPath + filenumber)
  552. # Check that all the manifest filenames
  553. # have a correct full path (no multiple '/').
  554. manifestFileList = re.findall(r"%s.*MANIFEST-\d+" % dbPath, data)
  555. self.assertTrue(len(manifestFileList) >= 1)
  556. for manifestFilename in manifestFileList:
  557. filenumber = re.findall(r"(?<=MANIFEST-)\d+", manifestFilename)[0]
  558. self.assertEqual(manifestFilename, dbPath + "MANIFEST-" + filenumber)
  559. # Check that the blob file index is decoded.
  560. decodedBlobIndex = re.findall(r"\[blob ref\]", data)
  561. self.assertTrue(len(decodedBlobIndex) >= 1)
  562. def listLiveFilesMetadata(self, params, dumpFile):
  563. return 0 == run_err_null(
  564. "./ldb list_live_files_metadata {} > {}".format(params, dumpFile)
  565. )
  566. def testListLiveFilesMetadata(self):
  567. print("Running testListLiveFilesMetadata...")
  568. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  569. self.assertRunOK("put x1 y1 --create_if_missing", "OK")
  570. self.assertRunOK("put x2 y2", "OK")
  571. # Compare the SST filename and the level of list_live_files_metadata
  572. # with the data collected from dump_live_files.
  573. dumpFilePath1 = os.path.join(self.TMP_DIR, "dump1")
  574. self.assertTrue(self.dumpLiveFiles("--db=%s" % dbPath, dumpFilePath1))
  575. dumpFilePath2 = os.path.join(self.TMP_DIR, "dump2")
  576. self.assertTrue(
  577. self.listLiveFilesMetadata(
  578. "--sort_by_filename --db=%s" % dbPath, dumpFilePath2
  579. )
  580. )
  581. # Collect SST filename and level from dump_live_files
  582. with open(dumpFilePath1) as tmp:
  583. data = tmp.read()
  584. filename1 = re.findall(r".*\d+\.sst", data)[0]
  585. level1 = re.findall(r"level:\d+", data)[0].split(":")[1]
  586. # Collect SST filename and level from list_live_files_metadata
  587. with open(dumpFilePath2) as tmp:
  588. data = tmp.read()
  589. filename2 = re.findall(r".*\d+\.sst", data)[0]
  590. level2 = re.findall(r"level \d+", data)[0].split(" ")[1]
  591. # Assert equality between filenames and levels.
  592. self.assertEqual(filename1, filename2)
  593. self.assertEqual(level1, level2)
  594. # Create multiple column families and compare the output
  595. # of list_live_files_metadata with dump_live_files once again.
  596. # Create new CF, and insert data:
  597. self.assertRunOK("create_column_family mycol1", "OK")
  598. self.assertRunOK("put --column_family=mycol1 v1 v2", "OK")
  599. self.assertRunOK("create_column_family mycol2", "OK")
  600. self.assertRunOK("put --column_family=mycol2 h1 h2", "OK")
  601. self.assertRunOK("put --column_family=mycol2 h3 h4", "OK")
  602. # Call dump_live_files and list_live_files_metadata
  603. # and pipe the output to compare them later.
  604. dumpFilePath3 = os.path.join(self.TMP_DIR, "dump3")
  605. self.assertTrue(self.dumpLiveFiles("--db=%s" % dbPath, dumpFilePath3))
  606. dumpFilePath4 = os.path.join(self.TMP_DIR, "dump4")
  607. self.assertTrue(
  608. self.listLiveFilesMetadata(
  609. "--sort_by_filename --db=%s" % dbPath, dumpFilePath4
  610. )
  611. )
  612. # dump_live_files:
  613. # parse the output and create a map:
  614. # [key: sstFilename]->[value:[LSM level, Column Family Name]]
  615. referenceMap = {}
  616. with open(dumpFilePath3) as tmp:
  617. data = tmp.read()
  618. # Note: the following regex are contingent on what the
  619. # dump_live_files outputs.
  620. namesAndLevels = re.findall(r"\d+.sst level:\d+", data)
  621. cfs = re.findall(r"(?<=column family name=)\w+", data)
  622. # re.findall should not reorder the data.
  623. # Therefore namesAndLevels[i] matches the data from cfs[i].
  624. for count, nameAndLevel in enumerate(namesAndLevels):
  625. sstFilename = re.findall(r"\d+.sst", nameAndLevel)[0]
  626. sstLevel = re.findall(r"(?<=level:)\d+", nameAndLevel)[0]
  627. cf = cfs[count]
  628. referenceMap[sstFilename] = [sstLevel, cf]
  629. # list_live_files_metadata:
  630. # parse the output and create a map:
  631. # [key: sstFilename]->[value:[LSM level, Column Family Name]]
  632. testMap = {}
  633. with open(dumpFilePath4) as tmp:
  634. data = tmp.read()
  635. # Since for each SST file, all the information is contained
  636. # on one line, the parsing is easy to perform and relies on
  637. # the appearance of an "00xxx.sst" pattern.
  638. sstLines = re.findall(r".*\d+.sst.*", data)
  639. for line in sstLines:
  640. sstFilename = re.findall(r"\d+.sst", line)[0]
  641. sstLevel = re.findall(r"(?<=level )\d+", line)[0]
  642. cf = re.findall(r"(?<=column family \')\w+(?=\')", line)[0]
  643. testMap[sstFilename] = [sstLevel, cf]
  644. # Compare the map obtained from dump_live_files and the map
  645. # obtained from list_live_files_metadata. Everything should match.
  646. self.assertEqual(referenceMap, testMap)
  647. def getManifests(self, directory):
  648. return glob.glob(directory + "/MANIFEST-*")
  649. def getSSTFiles(self, directory):
  650. return glob.glob(directory + "/*.sst")
  651. def getWALFiles(self, directory):
  652. return glob.glob(directory + "/*.log")
  653. def getBlobFiles(self, directory):
  654. return glob.glob(directory + "/*.blob")
  655. def copyManifests(self, src, dest):
  656. return 0 == run_err_null("cp " + src + " " + dest)
  657. def testManifestDump(self):
  658. print("Running testManifestDump...")
  659. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  660. self.assertRunOK("put 1 1 --create_if_missing", "OK")
  661. self.assertRunOK("put 2 2", "OK")
  662. self.assertRunOK("put 3 3", "OK")
  663. # Pattern to expect from manifest_dump.
  664. num = "[0-9]+"
  665. st = ".*"
  666. subpat = st + " seq:" + num + ", type:" + num
  667. regex = num + ":" + num + r"\[" + subpat + ".." + subpat + r"\]"
  668. expected_pattern = re.compile(regex)
  669. cmd = "manifest_dump --db=%s"
  670. manifest_files = self.getManifests(dbPath)
  671. self.assertTrue(len(manifest_files) == 1)
  672. # Test with the default manifest file in dbPath.
  673. self.assertRunOKFull(
  674. cmd % dbPath, expected_pattern, unexpected=False, isPattern=True
  675. )
  676. self.copyManifests(manifest_files[0], manifest_files[0] + "1")
  677. manifest_files = self.getManifests(dbPath)
  678. self.assertTrue(len(manifest_files) == 2)
  679. # Test with multiple manifest files in dbPath.
  680. self.assertRunFAILFull(cmd % dbPath)
  681. # Running it with the copy we just created should pass.
  682. self.assertRunOKFull(
  683. (cmd + " --path=%s") % (dbPath, manifest_files[1]),
  684. expected_pattern,
  685. unexpected=False,
  686. isPattern=True,
  687. )
  688. # Make sure that using the dump with --path will result in identical
  689. # output as just using manifest_dump.
  690. cmd = "dump --path=%s"
  691. self.assertRunOKFull(
  692. (cmd) % (manifest_files[1]),
  693. expected_pattern,
  694. unexpected=False,
  695. isPattern=True,
  696. )
  697. # Check if null characters doesn't infer with output format.
  698. self.assertRunOK("put a1 b1", "OK")
  699. self.assertRunOK("put a2 b2", "OK")
  700. self.assertRunOK("put --hex 0x12000DA0 0x80C0000B", "OK")
  701. self.assertRunOK("put --hex 0x7200004f 0x80000004", "OK")
  702. self.assertRunOK("put --hex 0xa000000a 0xf000000f", "OK")
  703. self.assertRunOK("put a3 b3", "OK")
  704. self.assertRunOK("put a4 b4", "OK")
  705. # Verifies that all "levels" are printed out.
  706. # There should be 66 mentions of levels.
  707. expected_verbose_output = re.compile("matched")
  708. # Test manifest_dump verbose and verify that key 0x7200004f
  709. # is present. Note that we are forced to use grep here because
  710. # an output with a non-terminating null character in it isn't piped
  711. # correctly through the Python subprocess object.
  712. # Also note that 0x72=r and 0x4f=O, hence the regex \'r.{2}O\'
  713. # (we cannot use null character in the subprocess input either,
  714. # so we have to use '.{2}')
  715. cmd_verbose = (
  716. "manifest_dump --verbose --db=%s | grep -aq $''r.{2}O'' && echo 'matched' || echo 'not matched'"
  717. % dbPath
  718. )
  719. self.assertRunOKFull(
  720. cmd_verbose, expected_verbose_output, unexpected=False, isPattern=True
  721. )
  722. def testGetProperty(self):
  723. print("Running testGetProperty...")
  724. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  725. self.assertRunOK("put 1 1 --create_if_missing", "OK")
  726. self.assertRunOK("put 2 2", "OK")
  727. # A "string" property
  728. cmd = "--db=%s get_property rocksdb.estimate-num-keys"
  729. self.assertRunOKFull(cmd % dbPath, "rocksdb.estimate-num-keys: 2")
  730. # A "map" property
  731. # FIXME: why doesn't this pick up two entries?
  732. cmd = "--db=%s get_property rocksdb.aggregated-table-properties"
  733. part = "rocksdb.aggregated-table-properties.num_entries: "
  734. expected_pattern = re.compile(part)
  735. self.assertRunOKFull(
  736. cmd % dbPath, expected_pattern, unexpected=False, isPattern=True
  737. )
  738. # An invalid property
  739. cmd = "--db=%s get_property rocksdb.this-property-does-not-exist"
  740. self.assertRunFAILFull(cmd % dbPath)
  741. def testSSTDump(self):
  742. print("Running testSSTDump...")
  743. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  744. self.assertRunOK("put sst1 sst1_val --create_if_missing", "OK")
  745. self.assertRunOK("put sst2 sst2_val --enable_blob_files", "OK")
  746. self.assertRunOK("get sst1", "sst1_val")
  747. # Pattern to expect from SST dump.
  748. regex = ".*Sst file format:.*\n.*\\[blob ref\\].*"
  749. expected_pattern = re.compile(regex)
  750. sst_files = self.getSSTFiles(dbPath)
  751. self.assertTrue(len(sst_files) >= 1)
  752. cmd = "dump --path=%s --decode_blob_index"
  753. self.assertRunOKFull(
  754. (cmd) % (sst_files[0]), expected_pattern, unexpected=False, isPattern=True
  755. )
  756. def testBlobDump(self):
  757. print("Running testBlobDump")
  758. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  759. self.assertRunOK("batchput x1 y1 --create_if_missing --enable_blob_files", "OK")
  760. self.assertRunOK(
  761. 'batchput --enable_blob_files x2 y2 x3 y3 "x4 abc" "y4 xyz"', "OK"
  762. )
  763. # Pattern to expect from blob file dump.
  764. regex = r".*Blob log header[\s\S]*Blob log footer[\s\S]*Read record[\s\S]*Summary" # noqa
  765. expected_pattern = re.compile(regex)
  766. blob_files = self.getBlobFiles(dbPath)
  767. self.assertTrue(len(blob_files) >= 1)
  768. cmd = "dump --path=%s --dump_uncompressed_blobs"
  769. self.assertRunOKFull(
  770. (cmd) % (blob_files[0]), expected_pattern, unexpected=False, isPattern=True
  771. )
  772. def testWALDump(self):
  773. print("Running testWALDump...")
  774. dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
  775. self.assertRunOK("put wal1 wal1_val --create_if_missing", "OK")
  776. self.assertRunOK("put wal2 wal2_val", "OK")
  777. self.assertRunOK("get wal1", "wal1_val")
  778. # Pattern to expect from WAL dump.
  779. regex = r"^Sequence,Count,ByteSize,Physical Offset,Key\(s\).*"
  780. expected_pattern = re.compile(regex)
  781. wal_files = self.getWALFiles(dbPath)
  782. self.assertTrue(len(wal_files) >= 1)
  783. cmd = "dump --path=%s"
  784. self.assertRunOKFull(
  785. (cmd) % (wal_files[0]), expected_pattern, unexpected=False, isPattern=True
  786. )
  787. def testListColumnFamilies(self):
  788. print("Running testListColumnFamilies...")
  789. self.assertRunOK("put x1 y1 --create_if_missing", "OK")
  790. cmd = 'list_column_families | grep -v "Column families"'
  791. # Test on valid dbPath.
  792. self.assertRunOK(cmd, "{default}")
  793. # Test on empty path.
  794. self.assertRunFAIL(cmd)
  795. def testColumnFamilies(self):
  796. print("Running testColumnFamilies...")
  797. _ = os.path.join(self.TMP_DIR, self.DB_NAME)
  798. self.assertRunOK("put cf1_1 1 --create_if_missing", "OK")
  799. self.assertRunOK("put cf1_2 2 --create_if_missing", "OK")
  800. self.assertRunOK("put cf1_3 3 --try_load_options", "OK")
  801. # Given non-default column family to single CF DB.
  802. self.assertRunFAIL("get cf1_1 --column_family=two")
  803. self.assertRunOK("create_column_family two", "OK")
  804. self.assertRunOK("put cf2_1 1 --create_if_missing --column_family=two", "OK")
  805. self.assertRunOK("put cf2_2 2 --create_if_missing --column_family=two", "OK")
  806. self.assertRunOK("delete cf1_2", "OK")
  807. self.assertRunOK("create_column_family three", "OK")
  808. self.assertRunOK("delete cf2_2 --column_family=two", "OK")
  809. self.assertRunOK("put cf3_1 3 --create_if_missing --column_family=three", "OK")
  810. self.assertRunOK("get cf1_1 --column_family=default", "1")
  811. self.assertRunOK("dump --column_family=two", "cf2_1 ==> 1\nKeys in range: 1")
  812. self.assertRunOK(
  813. "dump --column_family=two --try_load_options",
  814. "cf2_1 ==> 1\nKeys in range: 1",
  815. )
  816. self.assertRunOK("dump", "cf1_1 ==> 1\ncf1_3 ==> 3\nKeys in range: 2")
  817. self.assertRunOK("get cf2_1 --column_family=two", "1")
  818. self.assertRunOK("get cf3_1 --column_family=three", "3")
  819. self.assertRunOK("drop_column_family three", "OK")
  820. # non-existing column family.
  821. self.assertRunFAIL("get cf3_1 --column_family=four")
  822. self.assertRunFAIL("drop_column_family four")
  823. def testIngestExternalSst(self):
  824. print("Running testIngestExternalSst...")
  825. # Dump, load, write external sst and ingest it in another db
  826. dbPath = os.path.join(self.TMP_DIR, "db1")
  827. self.assertRunOK(
  828. "batchput --db=%s --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4" % dbPath,
  829. "OK",
  830. )
  831. self.assertRunOK(
  832. "scan --db=%s" % dbPath, "x1 ==> y1\nx2 ==> y2\nx3 ==> y3\nx4 ==> y4"
  833. )
  834. dumpFilePath = os.path.join(self.TMP_DIR, "dump1")
  835. with open(dumpFilePath, "w") as f:
  836. f.write("x1 ==> y10\nx2 ==> y20\nx3 ==> y30\nx4 ==> y40")
  837. externSstPath = os.path.join(self.TMP_DIR, "extern_data1.sst")
  838. self.assertTrue(
  839. self.writeExternSst(
  840. "--create_if_missing --db=%s" % dbPath, dumpFilePath, externSstPath
  841. )
  842. )
  843. # cannot ingest if allow_global_seqno is false
  844. self.assertFalse(
  845. self.ingestExternSst(
  846. "--create_if_missing --allow_global_seqno=false --db=%s" % dbPath,
  847. externSstPath,
  848. )
  849. )
  850. self.assertTrue(
  851. self.ingestExternSst(
  852. "--create_if_missing --allow_global_seqno --db=%s" % dbPath,
  853. externSstPath,
  854. )
  855. )
  856. self.assertRunOKFull(
  857. "scan --db=%s" % dbPath, "x1 ==> y10\nx2 ==> y20\nx3 ==> y30\nx4 ==> y40"
  858. )
  859. if __name__ == "__main__":
  860. unittest.main()