MCPcopy Create free account
hub / github.com/couchbase/moss / createStoreAndWriteNItems

Function createStoreAndWriteNItems

benchmark_get_test.go:63–112  ·  view source on GitHub ↗

---------------------------------------------------------------

(tmpDir string, items int,
	batches int)

Source from the content-addressed store, hash-verified

61// ---------------------------------------------------------------
62
63func createStoreAndWriteNItems(tmpDir string, items int,
64 batches int) (s *Store, c Collection, ks [][]byte) {
65
66 store, coll, err := OpenStoreCollection(tmpDir,
67 StoreOptions{},
68 StorePersistOptions{})
69
70 if err != nil || store == nil {
71 panic("OpenStoreCollection() failed!")
72 }
73
74 keys := make([][]byte, items)
75
76 if batches > items {
77 batches = 1
78 }
79 itemsPerBatch := items / batches
80 itemCount := 0
81
82 for i := 0; i < batches; i++ {
83 if itemsPerBatch > items-itemCount {
84 itemsPerBatch = items - itemCount
85 }
86
87 if itemsPerBatch <= 0 {
88 break
89 }
90
91 batch, err := coll.NewBatch(itemsPerBatch, itemsPerBatch*20)
92 if err != nil {
93 panic("NewBatch() failed!")
94 }
95
96 for j := 0; j < itemsPerBatch; j++ {
97 k := []byte(fmt.Sprintf("key%d", i))
98 v := []byte(fmt.Sprintf("val%d", i))
99 itemCount++
100
101 batch.Set(k, v)
102 keys[j] = k
103 }
104
105 err = coll.ExecuteBatch(batch, WriteOptions{})
106 if err != nil {
107 panic("ExecuteBatch() failed!")
108 }
109 }
110
111 return store, coll, keys
112}

Callers 2

BenchmarkCollectionGetsFunction · 0.85

Calls 4

SetMethod · 0.95
OpenStoreCollectionFunction · 0.85
NewBatchMethod · 0.65
ExecuteBatchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…