key_index_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package mvcc
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func TestKeyIndexGet(t *testing.T) {
  20. // key: "foo"
  21. // rev: 16
  22. // generations:
  23. // {empty}
  24. // {{14, 0}[1], {14, 1}[2], {16, 0}(t)[3]}
  25. // {{8, 0}[1], {10, 0}[2], {12, 0}(t)[3]}
  26. // {{2, 0}[1], {4, 0}[2], {6, 0}(t)[3]}
  27. ki := newTestKeyIndex()
  28. ki.compact(4, make(map[revision]struct{}))
  29. tests := []struct {
  30. rev int64
  31. wmod revision
  32. wcreat revision
  33. wver int64
  34. werr error
  35. }{
  36. {17, revision{}, revision{}, 0, ErrRevisionNotFound},
  37. {16, revision{}, revision{}, 0, ErrRevisionNotFound},
  38. // get on generation 3
  39. {15, revision{14, 1}, revision{14, 0}, 2, nil},
  40. {14, revision{14, 1}, revision{14, 0}, 2, nil},
  41. {13, revision{}, revision{}, 0, ErrRevisionNotFound},
  42. {12, revision{}, revision{}, 0, ErrRevisionNotFound},
  43. // get on generation 2
  44. {11, revision{10, 0}, revision{8, 0}, 2, nil},
  45. {10, revision{10, 0}, revision{8, 0}, 2, nil},
  46. {9, revision{8, 0}, revision{8, 0}, 1, nil},
  47. {8, revision{8, 0}, revision{8, 0}, 1, nil},
  48. {7, revision{}, revision{}, 0, ErrRevisionNotFound},
  49. {6, revision{}, revision{}, 0, ErrRevisionNotFound},
  50. // get on generation 1
  51. {5, revision{4, 0}, revision{2, 0}, 2, nil},
  52. {4, revision{4, 0}, revision{2, 0}, 2, nil},
  53. {3, revision{}, revision{}, 0, ErrRevisionNotFound},
  54. {2, revision{}, revision{}, 0, ErrRevisionNotFound},
  55. {1, revision{}, revision{}, 0, ErrRevisionNotFound},
  56. {0, revision{}, revision{}, 0, ErrRevisionNotFound},
  57. }
  58. for i, tt := range tests {
  59. mod, creat, ver, err := ki.get(tt.rev)
  60. if err != tt.werr {
  61. t.Errorf("#%d: err = %v, want %v", i, err, tt.werr)
  62. }
  63. if mod != tt.wmod {
  64. t.Errorf("#%d: modified = %+v, want %+v", i, mod, tt.wmod)
  65. }
  66. if creat != tt.wcreat {
  67. t.Errorf("#%d: created = %+v, want %+v", i, creat, tt.wcreat)
  68. }
  69. if ver != tt.wver {
  70. t.Errorf("#%d: version = %d, want %d", i, ver, tt.wver)
  71. }
  72. }
  73. }
  74. func TestKeyIndexSince(t *testing.T) {
  75. ki := newTestKeyIndex()
  76. ki.compact(4, make(map[revision]struct{}))
  77. allRevs := []revision{{4, 0}, {6, 0}, {8, 0}, {10, 0}, {12, 0}, {14, 1}, {16, 0}}
  78. tests := []struct {
  79. rev int64
  80. wrevs []revision
  81. }{
  82. {17, nil},
  83. {16, allRevs[6:]},
  84. {15, allRevs[6:]},
  85. {14, allRevs[5:]},
  86. {13, allRevs[5:]},
  87. {12, allRevs[4:]},
  88. {11, allRevs[4:]},
  89. {10, allRevs[3:]},
  90. {9, allRevs[3:]},
  91. {8, allRevs[2:]},
  92. {7, allRevs[2:]},
  93. {6, allRevs[1:]},
  94. {5, allRevs[1:]},
  95. {4, allRevs},
  96. {3, allRevs},
  97. {2, allRevs},
  98. {1, allRevs},
  99. {0, allRevs},
  100. }
  101. for i, tt := range tests {
  102. revs := ki.since(tt.rev)
  103. if !reflect.DeepEqual(revs, tt.wrevs) {
  104. t.Errorf("#%d: revs = %+v, want %+v", i, revs, tt.wrevs)
  105. }
  106. }
  107. }
  108. func TestKeyIndexPut(t *testing.T) {
  109. ki := &keyIndex{key: []byte("foo")}
  110. ki.put(5, 0)
  111. wki := &keyIndex{
  112. key: []byte("foo"),
  113. modified: revision{5, 0},
  114. generations: []generation{{created: revision{5, 0}, ver: 1, revs: []revision{{main: 5}}}},
  115. }
  116. if !reflect.DeepEqual(ki, wki) {
  117. t.Errorf("ki = %+v, want %+v", ki, wki)
  118. }
  119. ki.put(7, 0)
  120. wki = &keyIndex{
  121. key: []byte("foo"),
  122. modified: revision{7, 0},
  123. generations: []generation{{created: revision{5, 0}, ver: 2, revs: []revision{{main: 5}, {main: 7}}}},
  124. }
  125. if !reflect.DeepEqual(ki, wki) {
  126. t.Errorf("ki = %+v, want %+v", ki, wki)
  127. }
  128. }
  129. func TestKeyIndexRestore(t *testing.T) {
  130. ki := &keyIndex{key: []byte("foo")}
  131. ki.restore(revision{5, 0}, revision{7, 0}, 2)
  132. wki := &keyIndex{
  133. key: []byte("foo"),
  134. modified: revision{7, 0},
  135. generations: []generation{{created: revision{5, 0}, ver: 2, revs: []revision{{main: 7}}}},
  136. }
  137. if !reflect.DeepEqual(ki, wki) {
  138. t.Errorf("ki = %+v, want %+v", ki, wki)
  139. }
  140. }
  141. func TestKeyIndexTombstone(t *testing.T) {
  142. ki := &keyIndex{key: []byte("foo")}
  143. ki.put(5, 0)
  144. err := ki.tombstone(7, 0)
  145. if err != nil {
  146. t.Errorf("unexpected tombstone error: %v", err)
  147. }
  148. wki := &keyIndex{
  149. key: []byte("foo"),
  150. modified: revision{7, 0},
  151. generations: []generation{{created: revision{5, 0}, ver: 2, revs: []revision{{main: 5}, {main: 7}}}, {}},
  152. }
  153. if !reflect.DeepEqual(ki, wki) {
  154. t.Errorf("ki = %+v, want %+v", ki, wki)
  155. }
  156. ki.put(8, 0)
  157. ki.put(9, 0)
  158. err = ki.tombstone(15, 0)
  159. if err != nil {
  160. t.Errorf("unexpected tombstone error: %v", err)
  161. }
  162. wki = &keyIndex{
  163. key: []byte("foo"),
  164. modified: revision{15, 0},
  165. generations: []generation{
  166. {created: revision{5, 0}, ver: 2, revs: []revision{{main: 5}, {main: 7}}},
  167. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 9}, {main: 15}}},
  168. {},
  169. },
  170. }
  171. if !reflect.DeepEqual(ki, wki) {
  172. t.Errorf("ki = %+v, want %+v", ki, wki)
  173. }
  174. err = ki.tombstone(16, 0)
  175. if err != ErrRevisionNotFound {
  176. t.Errorf("tombstone error = %v, want %v", err, ErrRevisionNotFound)
  177. }
  178. }
  179. func TestKeyIndexCompact(t *testing.T) {
  180. tests := []struct {
  181. compact int64
  182. wki *keyIndex
  183. wam map[revision]struct{}
  184. }{
  185. {
  186. 1,
  187. &keyIndex{
  188. key: []byte("foo"),
  189. modified: revision{16, 0},
  190. generations: []generation{
  191. {created: revision{2, 0}, ver: 3, revs: []revision{{main: 2}, {main: 4}, {main: 6}}},
  192. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  193. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  194. {},
  195. },
  196. },
  197. map[revision]struct{}{},
  198. },
  199. {
  200. 2,
  201. &keyIndex{
  202. key: []byte("foo"),
  203. modified: revision{16, 0},
  204. generations: []generation{
  205. {created: revision{2, 0}, ver: 3, revs: []revision{{main: 2}, {main: 4}, {main: 6}}},
  206. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  207. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  208. {},
  209. },
  210. },
  211. map[revision]struct{}{
  212. revision{main: 2}: {},
  213. },
  214. },
  215. {
  216. 3,
  217. &keyIndex{
  218. key: []byte("foo"),
  219. modified: revision{16, 0},
  220. generations: []generation{
  221. {created: revision{2, 0}, ver: 3, revs: []revision{{main: 2}, {main: 4}, {main: 6}}},
  222. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  223. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  224. {},
  225. },
  226. },
  227. map[revision]struct{}{
  228. revision{main: 2}: {},
  229. },
  230. },
  231. {
  232. 4,
  233. &keyIndex{
  234. key: []byte("foo"),
  235. modified: revision{16, 0},
  236. generations: []generation{
  237. {created: revision{2, 0}, ver: 3, revs: []revision{{main: 4}, {main: 6}}},
  238. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  239. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  240. {},
  241. },
  242. },
  243. map[revision]struct{}{
  244. revision{main: 4}: {},
  245. },
  246. },
  247. {
  248. 5,
  249. &keyIndex{
  250. key: []byte("foo"),
  251. modified: revision{16, 0},
  252. generations: []generation{
  253. {created: revision{2, 0}, ver: 3, revs: []revision{{main: 4}, {main: 6}}},
  254. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  255. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  256. {},
  257. },
  258. },
  259. map[revision]struct{}{
  260. revision{main: 4}: {},
  261. },
  262. },
  263. {
  264. 6,
  265. &keyIndex{
  266. key: []byte("foo"),
  267. modified: revision{16, 0},
  268. generations: []generation{
  269. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  270. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  271. {},
  272. },
  273. },
  274. map[revision]struct{}{},
  275. },
  276. {
  277. 7,
  278. &keyIndex{
  279. key: []byte("foo"),
  280. modified: revision{16, 0},
  281. generations: []generation{
  282. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  283. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  284. {},
  285. },
  286. },
  287. map[revision]struct{}{},
  288. },
  289. {
  290. 8,
  291. &keyIndex{
  292. key: []byte("foo"),
  293. modified: revision{16, 0},
  294. generations: []generation{
  295. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  296. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  297. {},
  298. },
  299. },
  300. map[revision]struct{}{
  301. revision{main: 8}: {},
  302. },
  303. },
  304. {
  305. 9,
  306. &keyIndex{
  307. key: []byte("foo"),
  308. modified: revision{16, 0},
  309. generations: []generation{
  310. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},
  311. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  312. {},
  313. },
  314. },
  315. map[revision]struct{}{
  316. revision{main: 8}: {},
  317. },
  318. },
  319. {
  320. 10,
  321. &keyIndex{
  322. key: []byte("foo"),
  323. modified: revision{16, 0},
  324. generations: []generation{
  325. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 10}, {main: 12}}},
  326. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  327. {},
  328. },
  329. },
  330. map[revision]struct{}{
  331. revision{main: 10}: {},
  332. },
  333. },
  334. {
  335. 11,
  336. &keyIndex{
  337. key: []byte("foo"),
  338. modified: revision{16, 0},
  339. generations: []generation{
  340. {created: revision{8, 0}, ver: 3, revs: []revision{{main: 10}, {main: 12}}},
  341. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  342. {},
  343. },
  344. },
  345. map[revision]struct{}{
  346. revision{main: 10}: {},
  347. },
  348. },
  349. {
  350. 12,
  351. &keyIndex{
  352. key: []byte("foo"),
  353. modified: revision{16, 0},
  354. generations: []generation{
  355. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  356. {},
  357. },
  358. },
  359. map[revision]struct{}{},
  360. },
  361. {
  362. 13,
  363. &keyIndex{
  364. key: []byte("foo"),
  365. modified: revision{16, 0},
  366. generations: []generation{
  367. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},
  368. {},
  369. },
  370. },
  371. map[revision]struct{}{},
  372. },
  373. {
  374. 14,
  375. &keyIndex{
  376. key: []byte("foo"),
  377. modified: revision{16, 0},
  378. generations: []generation{
  379. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14, sub: 1}, {main: 16}}},
  380. {},
  381. },
  382. },
  383. map[revision]struct{}{
  384. revision{main: 14, sub: 1}: {},
  385. },
  386. },
  387. {
  388. 15,
  389. &keyIndex{
  390. key: []byte("foo"),
  391. modified: revision{16, 0},
  392. generations: []generation{
  393. {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14, sub: 1}, {main: 16}}},
  394. {},
  395. },
  396. },
  397. map[revision]struct{}{
  398. revision{main: 14, sub: 1}: {},
  399. },
  400. },
  401. {
  402. 16,
  403. &keyIndex{
  404. key: []byte("foo"),
  405. modified: revision{16, 0},
  406. generations: []generation{
  407. {},
  408. },
  409. },
  410. map[revision]struct{}{},
  411. },
  412. }
  413. // Continuous Compaction
  414. ki := newTestKeyIndex()
  415. for i, tt := range tests {
  416. am := make(map[revision]struct{})
  417. ki.compact(tt.compact, am)
  418. if !reflect.DeepEqual(ki, tt.wki) {
  419. t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)
  420. }
  421. if !reflect.DeepEqual(am, tt.wam) {
  422. t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)
  423. }
  424. }
  425. // Jump Compaction
  426. ki = newTestKeyIndex()
  427. for i, tt := range tests {
  428. if (i%2 == 0 && i < 6) || (i%2 == 1 && i > 6) {
  429. am := make(map[revision]struct{})
  430. ki.compact(tt.compact, am)
  431. if !reflect.DeepEqual(ki, tt.wki) {
  432. t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)
  433. }
  434. if !reflect.DeepEqual(am, tt.wam) {
  435. t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)
  436. }
  437. }
  438. }
  439. // Once Compaction
  440. for i, tt := range tests {
  441. ki := newTestKeyIndex()
  442. am := make(map[revision]struct{})
  443. ki.compact(tt.compact, am)
  444. if !reflect.DeepEqual(ki, tt.wki) {
  445. t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)
  446. }
  447. if !reflect.DeepEqual(am, tt.wam) {
  448. t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)
  449. }
  450. }
  451. }
  452. // test that compact on version that higher than last modified version works well
  453. func TestKeyIndexCompactOnFurtherRev(t *testing.T) {
  454. ki := &keyIndex{key: []byte("foo")}
  455. ki.put(1, 0)
  456. ki.put(2, 0)
  457. am := make(map[revision]struct{})
  458. ki.compact(3, am)
  459. wki := &keyIndex{
  460. key: []byte("foo"),
  461. modified: revision{2, 0},
  462. generations: []generation{
  463. {created: revision{1, 0}, ver: 2, revs: []revision{{main: 2}}},
  464. },
  465. }
  466. wam := map[revision]struct{}{
  467. revision{main: 2}: {},
  468. }
  469. if !reflect.DeepEqual(ki, wki) {
  470. t.Errorf("ki = %+v, want %+v", ki, wki)
  471. }
  472. if !reflect.DeepEqual(am, wam) {
  473. t.Errorf("am = %+v, want %+v", am, wam)
  474. }
  475. }
  476. func TestKeyIndexIsEmpty(t *testing.T) {
  477. tests := []struct {
  478. ki *keyIndex
  479. w bool
  480. }{
  481. {
  482. &keyIndex{
  483. key: []byte("foo"),
  484. generations: []generation{{}},
  485. },
  486. true,
  487. },
  488. {
  489. &keyIndex{
  490. key: []byte("foo"),
  491. modified: revision{2, 0},
  492. generations: []generation{
  493. {created: revision{1, 0}, ver: 2, revs: []revision{{main: 2}}},
  494. },
  495. },
  496. false,
  497. },
  498. }
  499. for i, tt := range tests {
  500. g := tt.ki.isEmpty()
  501. if g != tt.w {
  502. t.Errorf("#%d: isEmpty = %v, want %v", i, g, tt.w)
  503. }
  504. }
  505. }
  506. func TestKeyIndexFindGeneration(t *testing.T) {
  507. ki := newTestKeyIndex()
  508. tests := []struct {
  509. rev int64
  510. wg *generation
  511. }{
  512. {0, nil},
  513. {1, nil},
  514. {2, &ki.generations[0]},
  515. {3, &ki.generations[0]},
  516. {4, &ki.generations[0]},
  517. {5, &ki.generations[0]},
  518. {6, nil},
  519. {7, nil},
  520. {8, &ki.generations[1]},
  521. {9, &ki.generations[1]},
  522. {10, &ki.generations[1]},
  523. {11, &ki.generations[1]},
  524. {12, nil},
  525. {13, nil},
  526. }
  527. for i, tt := range tests {
  528. g := ki.findGeneration(tt.rev)
  529. if g != tt.wg {
  530. t.Errorf("#%d: generation = %+v, want %+v", i, g, tt.wg)
  531. }
  532. }
  533. }
  534. func TestKeyIndexLess(t *testing.T) {
  535. ki := &keyIndex{key: []byte("foo")}
  536. tests := []struct {
  537. ki *keyIndex
  538. w bool
  539. }{
  540. {&keyIndex{key: []byte("doo")}, false},
  541. {&keyIndex{key: []byte("foo")}, false},
  542. {&keyIndex{key: []byte("goo")}, true},
  543. }
  544. for i, tt := range tests {
  545. g := ki.Less(tt.ki)
  546. if g != tt.w {
  547. t.Errorf("#%d: Less = %v, want %v", i, g, tt.w)
  548. }
  549. }
  550. }
  551. func TestGenerationIsEmpty(t *testing.T) {
  552. tests := []struct {
  553. g *generation
  554. w bool
  555. }{
  556. {nil, true},
  557. {&generation{}, true},
  558. {&generation{revs: []revision{{main: 1}}}, false},
  559. }
  560. for i, tt := range tests {
  561. g := tt.g.isEmpty()
  562. if g != tt.w {
  563. t.Errorf("#%d: isEmpty = %v, want %v", i, g, tt.w)
  564. }
  565. }
  566. }
  567. func TestGenerationWalk(t *testing.T) {
  568. g := &generation{
  569. ver: 3,
  570. created: revision{2, 0},
  571. revs: []revision{{main: 2}, {main: 4}, {main: 6}},
  572. }
  573. tests := []struct {
  574. f func(rev revision) bool
  575. wi int
  576. }{
  577. {func(rev revision) bool { return rev.main >= 7 }, 2},
  578. {func(rev revision) bool { return rev.main >= 6 }, 1},
  579. {func(rev revision) bool { return rev.main >= 5 }, 1},
  580. {func(rev revision) bool { return rev.main >= 4 }, 0},
  581. {func(rev revision) bool { return rev.main >= 3 }, 0},
  582. {func(rev revision) bool { return rev.main >= 2 }, -1},
  583. }
  584. for i, tt := range tests {
  585. idx := g.walk(tt.f)
  586. if idx != tt.wi {
  587. t.Errorf("#%d: index = %d, want %d", i, idx, tt.wi)
  588. }
  589. }
  590. }
  591. func newTestKeyIndex() *keyIndex {
  592. // key: "foo"
  593. // rev: 16
  594. // generations:
  595. // {empty}
  596. // {{14, 0}[1], {14, 1}[2], {16, 0}(t)[3]}
  597. // {{8, 0}[1], {10, 0}[2], {12, 0}(t)[3]}
  598. // {{2, 0}[1], {4, 0}[2], {6, 0}(t)[3]}
  599. ki := &keyIndex{key: []byte("foo")}
  600. ki.put(2, 0)
  601. ki.put(4, 0)
  602. ki.tombstone(6, 0)
  603. ki.put(8, 0)
  604. ki.put(10, 0)
  605. ki.tombstone(12, 0)
  606. ki.put(14, 0)
  607. ki.put(14, 1)
  608. ki.tombstone(16, 0)
  609. return ki
  610. }