Skip to content

Commit

Permalink
added commit level to WritePolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
khaf committed Dec 22, 2014
1 parent bc0e4d8 commit 902fe0e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (

// This is the last of a multi-part message.
_INFO3_LAST int = (1 << 0)
// Commit to master only before declaring success.
_INFO3_COMMIT_MASTER int = (1 << 1)
// Update only. Merge bins.
_INFO3_UPDATE_ONLY int = (1 << 3)

Expand Down Expand Up @@ -580,6 +582,14 @@ func (cmd *baseCommand) writeHeaderWithPolicy(policy *WritePolicy, readAttr int,
break
}

if policy.CommitLevel == COMMIT_MASTER {
infoAttr |= _INFO3_COMMIT_MASTER
}

if policy.consistencyLevel == CONSISTENCY_ALL {
readAttr |= Command.INFO1_CONSISTENCY_ALL
}

// Write all header data except total size which must be written last.
cmd.dataBuffer[8] = _MSG_REMAINING_HEADER_SIZE // Message header length.
cmd.dataBuffer[9] = byte(readAttr)
Expand Down
29 changes: 29 additions & 0 deletions commit_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2012-2014 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package aerospike

// Desired consistency guarantee when committing a transaction on the server.
type CommitLevel int

const (
// Server should wait until successfully committing master and all replicas.
COMMIT_ALL CommitLevel = iota

// Server should wait until successfully committing master only.
COMMIT_MASTER
)
6 changes: 6 additions & 0 deletions write_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type WritePolicy struct {
// indicates that the generation is not used to restrict writes.
GenerationPolicy GenerationPolicy //= GenerationPolicy.NONE;

// Desired consistency guarantee when committing a transaction on the server. The default
// (COMMIT_ALL) indicates that the server should wait for master and all replica commits to
// be successful before returning success to the client.
CommitLevel CommitLevel //= COMMIT_ALL

// Generation determines expected generation.
// Generation is the number of times a record has been
// modified (including creation) on the server.
Expand All @@ -52,6 +57,7 @@ func NewWritePolicy(generation, expiration int32) *WritePolicy {
BasePolicy: *NewPolicy(),
RecordExistsAction: UPDATE,
GenerationPolicy: NONE,
CommitLevel: COMMIT_ALL,
Generation: generation,
Expiration: expiration,
SendKey: false,
Expand Down

0 comments on commit 902fe0e

Please sign in to comment.