kvstore_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. // Copyright 2015 CoreOS, Inc.
  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 storage
  15. import (
  16. "crypto/rand"
  17. "encoding/binary"
  18. "math"
  19. "os"
  20. "reflect"
  21. "testing"
  22. "time"
  23. "github.com/coreos/etcd/lease"
  24. "github.com/coreos/etcd/pkg/testutil"
  25. "github.com/coreos/etcd/storage/backend"
  26. "github.com/coreos/etcd/storage/storagepb"
  27. )
  28. func TestStoreRev(t *testing.T) {
  29. b, tmpPath := backend.NewDefaultTmpBackend()
  30. s := NewStore(b)
  31. defer os.Remove(tmpPath)
  32. for i := 0; i < 3; i++ {
  33. s.Put([]byte("foo"), []byte("bar"), NoLease)
  34. if r := s.Rev(); r != int64(i+1) {
  35. t.Errorf("#%d: rev = %d, want %d", i, r, i+1)
  36. }
  37. }
  38. }
  39. func TestStorePut(t *testing.T) {
  40. tests := []struct {
  41. rev revision
  42. r indexGetResp
  43. wrev revision
  44. wkey []byte
  45. wkv storagepb.KeyValue
  46. wputrev revision
  47. }{
  48. {
  49. revision{1, 0},
  50. indexGetResp{revision{}, revision{}, 0, ErrRevisionNotFound},
  51. revision{1, 1},
  52. newTestKeyBytes(revision{2, 0}, false),
  53. storagepb.KeyValue{
  54. Key: []byte("foo"),
  55. Value: []byte("bar"),
  56. CreateRevision: 2,
  57. ModRevision: 2,
  58. Version: 1,
  59. Lease: 1,
  60. },
  61. revision{2, 0},
  62. },
  63. {
  64. revision{1, 1},
  65. indexGetResp{revision{2, 0}, revision{2, 0}, 1, nil},
  66. revision{1, 2},
  67. newTestKeyBytes(revision{2, 1}, false),
  68. storagepb.KeyValue{
  69. Key: []byte("foo"),
  70. Value: []byte("bar"),
  71. CreateRevision: 2,
  72. ModRevision: 2,
  73. Version: 2,
  74. Lease: 2,
  75. },
  76. revision{2, 1},
  77. },
  78. {
  79. revision{2, 0},
  80. indexGetResp{revision{2, 1}, revision{2, 0}, 2, nil},
  81. revision{2, 1},
  82. newTestKeyBytes(revision{3, 0}, false),
  83. storagepb.KeyValue{
  84. Key: []byte("foo"),
  85. Value: []byte("bar"),
  86. CreateRevision: 2,
  87. ModRevision: 3,
  88. Version: 3,
  89. Lease: 3,
  90. },
  91. revision{3, 0},
  92. },
  93. }
  94. for i, tt := range tests {
  95. s := newFakeStore()
  96. b := s.b.(*fakeBackend)
  97. fi := s.kvindex.(*fakeIndex)
  98. s.currentRev = tt.rev
  99. s.tx = b.BatchTx()
  100. fi.indexGetRespc <- tt.r
  101. s.put([]byte("foo"), []byte("bar"), lease.LeaseID(i+1))
  102. data, err := tt.wkv.Marshal()
  103. if err != nil {
  104. t.Errorf("#%d: marshal err = %v, want nil", i, err)
  105. }
  106. wact := []testutil.Action{
  107. {"put", []interface{}{keyBucketName, tt.wkey, data}},
  108. }
  109. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  110. t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
  111. }
  112. wact = []testutil.Action{
  113. {"get", []interface{}{[]byte("foo"), tt.wputrev.main}},
  114. {"put", []interface{}{[]byte("foo"), tt.wputrev}},
  115. }
  116. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  117. t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
  118. }
  119. if s.currentRev != tt.wrev {
  120. t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
  121. }
  122. }
  123. }
  124. func TestStoreRange(t *testing.T) {
  125. key := newTestKeyBytes(revision{2, 0}, false)
  126. kv := storagepb.KeyValue{
  127. Key: []byte("foo"),
  128. Value: []byte("bar"),
  129. CreateRevision: 1,
  130. ModRevision: 2,
  131. Version: 1,
  132. }
  133. kvb, err := kv.Marshal()
  134. if err != nil {
  135. t.Fatal(err)
  136. }
  137. currev := revision{1, 1}
  138. wrev := int64(2)
  139. tests := []struct {
  140. idxr indexRangeResp
  141. r rangeResp
  142. }{
  143. {
  144. indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
  145. rangeResp{[][]byte{key}, [][]byte{kvb}},
  146. },
  147. {
  148. indexRangeResp{[][]byte{[]byte("foo"), []byte("foo1")}, []revision{{2, 0}, {3, 0}}},
  149. rangeResp{[][]byte{key}, [][]byte{kvb}},
  150. },
  151. }
  152. for i, tt := range tests {
  153. s := newFakeStore()
  154. b := s.b.(*fakeBackend)
  155. fi := s.kvindex.(*fakeIndex)
  156. s.currentRev = currev
  157. s.tx = b.BatchTx()
  158. b.tx.rangeRespc <- tt.r
  159. fi.indexRangeRespc <- tt.idxr
  160. kvs, rev, err := s.rangeKeys([]byte("foo"), []byte("goo"), 1, 0)
  161. if err != nil {
  162. t.Errorf("#%d: err = %v, want nil", i, err)
  163. }
  164. if w := []storagepb.KeyValue{kv}; !reflect.DeepEqual(kvs, w) {
  165. t.Errorf("#%d: kvs = %+v, want %+v", i, kvs, w)
  166. }
  167. if rev != wrev {
  168. t.Errorf("#%d: rev = %d, want %d", i, rev, wrev)
  169. }
  170. wstart, wend := revBytesRange(tt.idxr.revs[0])
  171. wact := []testutil.Action{
  172. {"range", []interface{}{keyBucketName, wstart, wend, int64(0)}},
  173. }
  174. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  175. t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
  176. }
  177. wact = []testutil.Action{
  178. {"range", []interface{}{[]byte("foo"), []byte("goo"), wrev}},
  179. }
  180. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  181. t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
  182. }
  183. if s.currentRev != currev {
  184. t.Errorf("#%d: current rev = %+v, want %+v", i, s.currentRev, currev)
  185. }
  186. }
  187. }
  188. func TestStoreDeleteRange(t *testing.T) {
  189. tests := []struct {
  190. rev revision
  191. r indexRangeResp
  192. wkey []byte
  193. wrev revision
  194. wrrev int64
  195. wdelrev revision
  196. }{
  197. {
  198. revision{2, 0},
  199. indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
  200. newTestKeyBytes(revision{3, 0}, true),
  201. revision{2, 1},
  202. 2,
  203. revision{3, 0},
  204. },
  205. {
  206. revision{2, 1},
  207. indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
  208. newTestKeyBytes(revision{3, 1}, true),
  209. revision{2, 2},
  210. 3,
  211. revision{3, 1},
  212. },
  213. }
  214. for i, tt := range tests {
  215. s := newFakeStore()
  216. b := s.b.(*fakeBackend)
  217. fi := s.kvindex.(*fakeIndex)
  218. s.currentRev = tt.rev
  219. s.tx = b.BatchTx()
  220. fi.indexRangeRespc <- tt.r
  221. n := s.deleteRange([]byte("foo"), []byte("goo"))
  222. if n != 1 {
  223. t.Errorf("#%d: n = %d, want 1", i, n)
  224. }
  225. data, err := (&storagepb.KeyValue{
  226. Key: []byte("foo"),
  227. }).Marshal()
  228. if err != nil {
  229. t.Errorf("#%d: marshal err = %v, want nil", i, err)
  230. }
  231. wact := []testutil.Action{
  232. {"put", []interface{}{keyBucketName, tt.wkey, data}},
  233. }
  234. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  235. t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
  236. }
  237. wact = []testutil.Action{
  238. {"range", []interface{}{[]byte("foo"), []byte("goo"), tt.wrrev}},
  239. {"tombstone", []interface{}{[]byte("foo"), tt.wdelrev}},
  240. }
  241. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  242. t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
  243. }
  244. if s.currentRev != tt.wrev {
  245. t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
  246. }
  247. }
  248. }
  249. func TestStoreCompact(t *testing.T) {
  250. s := newFakeStore()
  251. b := s.b.(*fakeBackend)
  252. fi := s.kvindex.(*fakeIndex)
  253. s.currentRev = revision{3, 0}
  254. fi.indexCompactRespc <- map[revision]struct{}{revision{1, 0}: {}}
  255. key1 := newTestKeyBytes(revision{1, 0}, false)
  256. key2 := newTestKeyBytes(revision{2, 0}, false)
  257. b.tx.rangeRespc <- rangeResp{[][]byte{key1, key2}, nil}
  258. s.Compact(3)
  259. s.wg.Wait()
  260. if s.compactMainRev != 3 {
  261. t.Errorf("compact main rev = %d, want 3", s.compactMainRev)
  262. }
  263. end := make([]byte, 8)
  264. binary.BigEndian.PutUint64(end, uint64(4))
  265. wact := []testutil.Action{
  266. {"put", []interface{}{metaBucketName, scheduledCompactKeyName, newTestRevBytes(revision{3, 0})}},
  267. {"range", []interface{}{keyBucketName, make([]byte, 17), end, int64(10000)}},
  268. {"delete", []interface{}{keyBucketName, key2}},
  269. {"put", []interface{}{metaBucketName, finishedCompactKeyName, newTestRevBytes(revision{3, 0})}},
  270. }
  271. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  272. t.Errorf("tx actions = %+v, want %+v", g, wact)
  273. }
  274. wact = []testutil.Action{
  275. {"compact", []interface{}{int64(3)}},
  276. }
  277. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  278. t.Errorf("index action = %+v, want %+v", g, wact)
  279. }
  280. }
  281. func TestStoreRestore(t *testing.T) {
  282. s := newFakeStore()
  283. b := s.b.(*fakeBackend)
  284. fi := s.kvindex.(*fakeIndex)
  285. putkey := newTestKeyBytes(revision{3, 0}, false)
  286. putkv := storagepb.KeyValue{
  287. Key: []byte("foo"),
  288. Value: []byte("bar"),
  289. CreateRevision: 3,
  290. ModRevision: 3,
  291. Version: 1,
  292. }
  293. putkvb, err := putkv.Marshal()
  294. if err != nil {
  295. t.Fatal(err)
  296. }
  297. delkey := newTestKeyBytes(revision{4, 0}, true)
  298. delkv := storagepb.KeyValue{
  299. Key: []byte("foo"),
  300. }
  301. delkvb, err := delkv.Marshal()
  302. if err != nil {
  303. t.Fatal(err)
  304. }
  305. b.tx.rangeRespc <- rangeResp{[][]byte{finishedCompactKeyName}, [][]byte{newTestRevBytes(revision{2, 0})}}
  306. b.tx.rangeRespc <- rangeResp{[][]byte{putkey, delkey}, [][]byte{putkvb, delkvb}}
  307. b.tx.rangeRespc <- rangeResp{[][]byte{scheduledCompactKeyName}, [][]byte{newTestRevBytes(revision{2, 0})}}
  308. s.restore()
  309. if s.compactMainRev != 2 {
  310. t.Errorf("compact rev = %d, want 4", s.compactMainRev)
  311. }
  312. wrev := revision{4, 0}
  313. if !reflect.DeepEqual(s.currentRev, wrev) {
  314. t.Errorf("current rev = %v, want %v", s.currentRev, wrev)
  315. }
  316. wact := []testutil.Action{
  317. {"range", []interface{}{metaBucketName, finishedCompactKeyName, []byte(nil), int64(0)}},
  318. {"range", []interface{}{keyBucketName, newTestRevBytes(revision{}), newTestRevBytes(revision{math.MaxInt64, math.MaxInt64}), int64(0)}},
  319. {"range", []interface{}{metaBucketName, scheduledCompactKeyName, []byte(nil), int64(0)}},
  320. }
  321. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  322. t.Errorf("tx actions = %+v, want %+v", g, wact)
  323. }
  324. wact = []testutil.Action{
  325. {"restore", []interface{}{[]byte("foo"), revision{3, 0}, revision{3, 0}, int64(1)}},
  326. {"tombstone", []interface{}{[]byte("foo"), revision{4, 0}}},
  327. }
  328. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  329. t.Errorf("index action = %+v, want %+v", g, wact)
  330. }
  331. }
  332. func TestRestoreContinueUnfinishedCompaction(t *testing.T) {
  333. b, tmpPath := backend.NewDefaultTmpBackend()
  334. s0 := NewStore(b)
  335. defer os.Remove(tmpPath)
  336. s0.Put([]byte("foo"), []byte("bar"), NoLease)
  337. s0.Put([]byte("foo"), []byte("bar1"), NoLease)
  338. s0.Put([]byte("foo"), []byte("bar2"), NoLease)
  339. // write scheduled compaction, but not do compaction
  340. rbytes := newRevBytes()
  341. revToBytes(revision{main: 2}, rbytes)
  342. tx := s0.b.BatchTx()
  343. tx.Lock()
  344. tx.UnsafePut(metaBucketName, scheduledCompactKeyName, rbytes)
  345. tx.Unlock()
  346. s0.Close()
  347. s1 := NewStore(b)
  348. // wait for scheduled compaction to be finished
  349. time.Sleep(100 * time.Millisecond)
  350. if _, _, err := s1.Range([]byte("foo"), nil, 0, 2); err != ErrCompacted {
  351. t.Errorf("range on compacted rev error = %v, want %v", err, ErrCompacted)
  352. }
  353. // check the key in backend is deleted
  354. revbytes := newRevBytes()
  355. // TODO: compact should delete main=2 key too
  356. revToBytes(revision{main: 1}, revbytes)
  357. // The disk compaction is done asynchronously and requires more time on slow disk.
  358. // try 5 times for CI with slow IO.
  359. for i := 0; i < 5; i++ {
  360. tx = s1.b.BatchTx()
  361. tx.Lock()
  362. ks, _ := tx.UnsafeRange(keyBucketName, revbytes, nil, 0)
  363. tx.Unlock()
  364. if len(ks) != 0 {
  365. time.Sleep(100 * time.Millisecond)
  366. continue
  367. }
  368. return
  369. }
  370. t.Errorf("key for rev %+v still exists, want deleted", bytesToRev(revbytes))
  371. }
  372. func TestTxnPut(t *testing.T) {
  373. // assign arbitrary size
  374. bytesN := 30
  375. sliceN := 100
  376. keys := createBytesSlice(bytesN, sliceN)
  377. vals := createBytesSlice(bytesN, sliceN)
  378. b, tmpPath := backend.NewDefaultTmpBackend()
  379. s := NewStore(b)
  380. defer cleanup(s, b, tmpPath)
  381. for i := 0; i < sliceN; i++ {
  382. id := s.TxnBegin()
  383. base := int64(i + 1)
  384. rev, err := s.TxnPut(id, keys[i], vals[i], NoLease)
  385. if err != nil {
  386. t.Error("txn put error")
  387. }
  388. if rev != base {
  389. t.Errorf("#%d: rev = %d, want %d", i, rev, base)
  390. }
  391. s.TxnEnd(id)
  392. }
  393. }
  394. func TestTxnBlockBackendForceCommit(t *testing.T) {
  395. b, tmpPath := backend.NewDefaultTmpBackend()
  396. s := NewStore(b)
  397. defer os.Remove(tmpPath)
  398. id := s.TxnBegin()
  399. done := make(chan struct{})
  400. go func() {
  401. s.b.ForceCommit()
  402. done <- struct{}{}
  403. }()
  404. select {
  405. case <-done:
  406. t.Fatalf("failed to block ForceCommit")
  407. case <-time.After(100 * time.Millisecond):
  408. }
  409. s.TxnEnd(id)
  410. select {
  411. case <-done:
  412. case <-time.After(time.Second):
  413. t.Fatalf("failed to execute ForceCommit")
  414. }
  415. }
  416. func newTestRevBytes(rev revision) []byte {
  417. bytes := newRevBytes()
  418. revToBytes(rev, bytes)
  419. return bytes
  420. }
  421. func newTestKeyBytes(rev revision, tombstone bool) []byte {
  422. bytes := newRevBytes()
  423. revToBytes(rev, bytes)
  424. if tombstone {
  425. bytes = appendMarkTombstone(bytes)
  426. }
  427. return bytes
  428. }
  429. func newFakeStore() *store {
  430. b := &fakeBackend{&fakeBatchTx{
  431. Recorder: &testutil.RecorderBuffered{},
  432. rangeRespc: make(chan rangeResp, 5)}}
  433. fi := &fakeIndex{
  434. Recorder: &testutil.RecorderBuffered{},
  435. indexGetRespc: make(chan indexGetResp, 1),
  436. indexRangeRespc: make(chan indexRangeResp, 1),
  437. indexRangeEventsRespc: make(chan indexRangeEventsResp, 1),
  438. indexCompactRespc: make(chan map[revision]struct{}, 1),
  439. }
  440. return &store{
  441. b: b,
  442. kvindex: fi,
  443. currentRev: revision{},
  444. compactMainRev: -1,
  445. }
  446. }
  447. type rangeResp struct {
  448. keys [][]byte
  449. vals [][]byte
  450. }
  451. type fakeBatchTx struct {
  452. testutil.Recorder
  453. rangeRespc chan rangeResp
  454. }
  455. func (b *fakeBatchTx) Lock() {}
  456. func (b *fakeBatchTx) Unlock() {}
  457. func (b *fakeBatchTx) UnsafeCreateBucket(name []byte) {}
  458. func (b *fakeBatchTx) UnsafePut(bucketName []byte, key []byte, value []byte) {
  459. b.Recorder.Record(testutil.Action{Name: "put", Params: []interface{}{bucketName, key, value}})
  460. }
  461. func (b *fakeBatchTx) UnsafeRange(bucketName []byte, key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) {
  462. b.Recorder.Record(testutil.Action{Name: "range", Params: []interface{}{bucketName, key, endKey, limit}})
  463. r := <-b.rangeRespc
  464. return r.keys, r.vals
  465. }
  466. func (b *fakeBatchTx) UnsafeDelete(bucketName []byte, key []byte) {
  467. b.Recorder.Record(testutil.Action{Name: "delete", Params: []interface{}{bucketName, key}})
  468. }
  469. func (b *fakeBatchTx) Commit() {}
  470. func (b *fakeBatchTx) CommitAndStop() {}
  471. type fakeBackend struct {
  472. tx *fakeBatchTx
  473. }
  474. func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
  475. func (b *fakeBackend) Hash() (uint32, error) { return 0, nil }
  476. func (b *fakeBackend) Size() int64 { return 0 }
  477. func (b *fakeBackend) Snapshot() backend.Snapshot { return nil }
  478. func (b *fakeBackend) ForceCommit() {}
  479. func (b *fakeBackend) Close() error { return nil }
  480. type indexGetResp struct {
  481. rev revision
  482. created revision
  483. ver int64
  484. err error
  485. }
  486. type indexRangeResp struct {
  487. keys [][]byte
  488. revs []revision
  489. }
  490. type indexRangeEventsResp struct {
  491. revs []revision
  492. }
  493. type fakeIndex struct {
  494. testutil.Recorder
  495. indexGetRespc chan indexGetResp
  496. indexRangeRespc chan indexRangeResp
  497. indexRangeEventsRespc chan indexRangeEventsResp
  498. indexCompactRespc chan map[revision]struct{}
  499. }
  500. func (i *fakeIndex) Get(key []byte, atRev int64) (rev, created revision, ver int64, err error) {
  501. i.Recorder.Record(testutil.Action{Name: "get", Params: []interface{}{key, atRev}})
  502. r := <-i.indexGetRespc
  503. return r.rev, r.created, r.ver, r.err
  504. }
  505. func (i *fakeIndex) Range(key, end []byte, atRev int64) ([][]byte, []revision) {
  506. i.Recorder.Record(testutil.Action{Name: "range", Params: []interface{}{key, end, atRev}})
  507. r := <-i.indexRangeRespc
  508. return r.keys, r.revs
  509. }
  510. func (i *fakeIndex) Put(key []byte, rev revision) {
  511. i.Recorder.Record(testutil.Action{Name: "put", Params: []interface{}{key, rev}})
  512. }
  513. func (i *fakeIndex) Restore(key []byte, created, modified revision, ver int64) {
  514. i.Recorder.Record(testutil.Action{Name: "restore", Params: []interface{}{key, created, modified, ver}})
  515. }
  516. func (i *fakeIndex) Tombstone(key []byte, rev revision) error {
  517. i.Recorder.Record(testutil.Action{Name: "tombstone", Params: []interface{}{key, rev}})
  518. return nil
  519. }
  520. func (i *fakeIndex) RangeSince(key, end []byte, rev int64) []revision {
  521. i.Recorder.Record(testutil.Action{Name: "rangeEvents", Params: []interface{}{key, end, rev}})
  522. r := <-i.indexRangeEventsRespc
  523. return r.revs
  524. }
  525. func (i *fakeIndex) Compact(rev int64) map[revision]struct{} {
  526. i.Recorder.Record(testutil.Action{Name: "compact", Params: []interface{}{rev}})
  527. return <-i.indexCompactRespc
  528. }
  529. func (i *fakeIndex) Equal(b index) bool { return false }
  530. func createBytesSlice(bytesN, sliceN int) [][]byte {
  531. rs := [][]byte{}
  532. for len(rs) != sliceN {
  533. v := make([]byte, bytesN)
  534. if _, err := rand.Read(v); err != nil {
  535. panic(err)
  536. }
  537. rs = append(rs, v)
  538. }
  539. return rs
  540. }