Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
add missing source file
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranrg committed Apr 26, 2017
1 parent e73cc29 commit f82b56a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions cmd/tools/cdb/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"math"

"github.com/uber/cherami-server/storage"
"github.com/uber/cherami-thrift/.generated/go/store"

"github.com/apache/thrift/lib/go/thrift"
)

// -- decode message/address -- //
const (
seqNumBits = 26

invalidKey = math.MaxInt64

seqNumBitmask = (int64(1) << seqNumBits) - 1
timestampBitmask = math.MaxInt64 &^ seqNumBitmask
seqNumMax = int64(math.MaxInt64-2) & seqNumBitmask

seqNumUnspecifiedSeal = int64(math.MaxInt64 - 1)
)

func deconstructKey(key storage.Key) (visibilityTime int64, seqNum int64) {
return int64(int64(key) & timestampBitmask), int64(int64(key) & seqNumBitmask)
}

func deconstructSealExtentKey(key storage.Key) (seqNum int64) {

seqNum = int64(key) & seqNumBitmask

// we use the special seqnum ('MaxInt64 - 1') when the extent has been sealed
// at an "unspecified" seqnum; check for this case, and return appropriate value
if seqNum == (seqNumBitmask - 1) {
seqNum = seqNumUnspecifiedSeal
}

return
}

func isSealExtentKey(key storage.Key) bool {
return key != storage.InvalidKey && (int64(key)&timestampBitmask) == timestampBitmask
}

func deserializeMessage(data []byte) (*store.AppendMessage, error) {
msg := &store.AppendMessage{}
deserializer := thrift.NewTDeserializer()
if err := deserializer.Read(msg, data); err != nil {
return nil, err
}

return msg, nil
}

0 comments on commit f82b56a

Please sign in to comment.