Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: ailinkid <[email protected]>
  • Loading branch information
AilinKid committed Aug 18, 2021
1 parent bd19369 commit 3896af7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var (
)

const (
// CurrentMagicByteVer is the current magic byte version.
CurrentMagicByteVer byte = 0x00
// PolicyMagicByte handler
// 0x00 - 0x3F: Json Handler
Expand All @@ -87,7 +88,7 @@ const (
// 0xC0 - 0xFF: Reserved

// type means how to handle the serialized data.
typeJson int = 1
typeJSON int = 1
typeUnknown int = 2
// todo: customized handler.
)
Expand Down Expand Up @@ -169,13 +170,15 @@ func (m *Meta) GetGlobalID() (int64, error) {
return m.txn.GetInt64(mNextGlobalIDKey)
}

// GenPolicyID generates the next policy global id.
func (m *Meta) GenPolicyID() (int64, error) {
policyIDMutex.Lock()
defer policyIDMutex.Unlock()

return m.txn.Inc(mPolicyGlobalID, 1)
}

// GetPolicyID gets current policy global id.
func (m *Meta) GetPolicyID() (int64, error) {
return m.txn.GetInt64(mPolicyGlobalID)
}
Expand Down Expand Up @@ -355,6 +358,7 @@ func (m *Meta) checkTableNotExists(dbKey []byte, tableKey []byte) error {
return errors.Trace(err)
}

// CreatePolicy creates a policy.
func (m *Meta) CreatePolicy(policy *placement.Policy) error {
policyKey := m.policyKey(policy.ID)

Expand All @@ -368,6 +372,7 @@ func (m *Meta) CreatePolicy(policy *placement.Policy) error {
return m.txn.HSet(mPolicies, policyKey, attachMagicByte(data))
}

// UpdatePolicy updates a policy.
func (m *Meta) UpdatePolicy(policy *placement.Policy) error {
policyKey := m.policyKey(policy.ID)

Expand Down Expand Up @@ -684,7 +689,7 @@ func attachMagicByte(data []byte) []byte {
func detachMagicByte(value []byte) ([]byte, error) {
magic, data := value[:1], value[1:]
switch whichMagicType(magic[0]) {
case typeJson:
case typeJSON:
return data, nil
default:
//
Expand Down

0 comments on commit 3896af7

Please sign in to comment.