@@ -2,6 +2,7 @@ package secretary
22
33import (
44 "bytes"
5+ "encoding/binary"
56 "fmt"
67 "sort"
78 "sync/atomic"
@@ -296,13 +297,22 @@ func (tree *BTree) splitInternal(node *Node) {
296297 tree .promoteKey (node , promotedKey , newRightInternal )
297298}
298299
299- // Set a Record key-value pair into the B+ Tree
300- func (tree * BTree ) Set (key []byte , value []byte ) error {
300+ func (tree * BTree ) Set (value []byte ) error {
301+ buf := make ([]byte , 16 )
302+ binary .BigEndian .PutUint64 (buf [8 :], tree .KeySeq )
303+ return tree .SetKV (buf , value )
304+ }
305+
306+ // SetKV a Record key-value pair into the B+ Tree
307+ func (tree * BTree ) SetKV (key []byte , value []byte ) error {
301308 if len (key ) != KEY_SIZE {
302309 return ErrorInvalidKey
303310 }
304311
305312 if tree .root == nil {
313+
314+ atomic .AddUint64 (& tree .KeySeq , KEY_INCREMENT )
315+
306316 tree .root = tree .createLeafNode ()
307317 tree .root .setLeafKV (key , value )
308318
@@ -314,6 +324,8 @@ func (tree *BTree) Set(key []byte, value []byte) error {
314324 return ErrorDuplicateKey
315325 }
316326
327+ atomic .AddUint64 (& tree .KeySeq , KEY_INCREMENT )
328+
317329 leaf .setLeafKV (key , value )
318330
319331 if len (leaf .Keys ) >= int (tree .Order ) {
@@ -364,7 +376,7 @@ func equiDivision(len int, max int) []int {
364376 ends [i ]++
365377 }
366378 }
367- // fmt.Println ("ends", ends)
379+ ServerLog ("ends" , ends )
368380 return ends
369381}
370382
@@ -377,13 +389,15 @@ func (tree *BTree) SortedRecordSet(sortedRecords []*Record) error {
377389 leafNodes := tree .buildSortedLeafNodes (sortedRecords )
378390 tree .root = tree .buildInternalNodes (leafNodes )
379391
392+ atomic .AddUint64 (& tree .KeySeq , KEY_INCREMENT * uint64 (len (sortedRecords )))
393+
380394 return nil
381395}
382396
383397func (tree * BTree ) buildSortedLeafNodes (sortedRecords []* Record ) []* Node {
384398 leafNodes := []* Node {}
385399
386- // fmt.Println ("---", len(sortedRecords))
400+ ServerLog ("---" , len (sortedRecords ))
387401 ends := equiDivision (len (sortedRecords ), int (tree .Order - 1 ))
388402
389403 end := 0
0 commit comments