MCPcopy
hub / github.com/dgraph-io/dgraph / TestBinSplit

Function TestBinSplit

posting/list_test.go:1223–1289  ·  view source on GitHub ↗

Checks if the binSplit works correctly.

(t *testing.T)

Source from the content-addressed store, hash-verified

1221
1222// Checks if the binSplit works correctly.
1223func TestBinSplit(t *testing.T) {
1224 createList := func(t *testing.T, size int) *List {
1225 // This is a package level constant, so reset it after use.
1226 originalListSize := maxListSize
1227 maxListSize = math.MaxInt32
1228 defer func() {
1229 maxListSize = originalListSize
1230 }()
1231 key := x.DataKey(x.AttrInRootNamespace(uuid.New().String()), 1331)
1232 ol, err := readPostingListFromDisk(key, ps, math.MaxUint64)
1233 require.NoError(t, err)
1234 for i := 1; i <= size; i++ {
1235 edge := &pb.DirectedEdge{
1236 ValueId: uint64(i),
1237 Facets: []*api.Facet{{Key: strconv.Itoa(i)}},
1238 }
1239 txn := Txn{StartTs: uint64(i)}
1240 addMutationHelper(t, ol, edge, Set, &txn)
1241 require.NoError(t, ol.commitMutation(uint64(i), uint64(i)+1))
1242 }
1243
1244 kvs, err := ol.Rollup(nil, math.MaxUint64)
1245 require.NoError(t, err)
1246 for _, kv := range kvs {
1247 require.Equal(t, uint64(size+1), kv.Version)
1248 }
1249 require.NoError(t, writePostingListToDisk(kvs))
1250 ol, err = readPostingListFromDisk(key, ps, math.MaxUint64)
1251 require.NoError(t, err)
1252 require.Equal(t, 0, len(ol.plist.Splits))
1253 require.Equal(t, size, len(ol.plist.Postings))
1254 return ol
1255 }
1256 verifyBinSplit := func(t *testing.T, ol *List, startUids []uint64, pls []*pb.PostingList) {
1257 require.Equal(t, 2, len(startUids))
1258 require.Equal(t, 2, len(pls))
1259 uids := codec.Decode(ol.plist.Pack, 0)
1260 lowUids := codec.Decode(pls[0].Pack, startUids[0])
1261 highUids := codec.Decode(pls[1].Pack, startUids[1])
1262 // Check if no data is lost in splitting.
1263 require.Equal(t, uids, append(lowUids, highUids...))
1264 require.Equal(t, ol.plist.Postings, append(pls[0].Postings, pls[1].Postings...))
1265 // Check if the postings belong to the correct half.
1266 midUid := pls[1].Pack.Blocks[0].GetBase()
1267 require.Equal(t, startUids[1], midUid)
1268 for _, p := range pls[0].Postings {
1269 require.Less(t, p.Uid, midUid)
1270 }
1271 for _, p := range pls[1].Postings {
1272 require.GreaterOrEqual(t, p.Uid, midUid)
1273 }
1274 }
1275 size := int(1e5)
1276 ol := createList(t, size)
1277 postings := ol.plist.Postings
1278 startUids, pls := binSplit(1, ol.plist)
1279 verifyBinSplit(t, ol, startUids, pls)
1280

Callers

nothing calls this directly

Calls 12

DataKeyFunction · 0.92
AttrInRootNamespaceFunction · 0.92
DecodeFunction · 0.92
addMutationHelperFunction · 0.85
binSplitFunction · 0.85
commitMutationMethod · 0.80
RollupMethod · 0.80
GetBaseMethod · 0.80
readPostingListFromDiskFunction · 0.70
writePostingListToDiskFunction · 0.70
StringMethod · 0.45
LessMethod · 0.45

Tested by

no test coverage detected