This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kiranrg
committed
Apr 26, 2017
1 parent
e73cc29
commit f82b56a
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)×tampBitmask) == 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 | ||
} |