_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q10000
Serialize
train
func (msg *Message) Serialize() []byte { msg.DataLen = msgLenToBytes(int64(len(msg.Data))) buf := bytes.NewBuffer([]byte{}) binary.Write(buf, binary.BigEndian, msg.MessageHeader) binary.Write(buf, binary.BigEndian, msg.Data[:]) return buf.Bytes() }
go
{ "resource": "" }
q10001
calcTPS
train
func calcTPS(count int, duration time.Duration) int { return int(float64(count) / (float64(duration) / float64(time.Second))) }
go
{ "resource": "" }
q10002
runMultiBinExample
train
func runMultiBinExample(client *as.Client) { key, _ := as.NewKey(*shared.Namespace, *shared.Set, "putgetkey") bin1 := as.NewBin("bin1", "value1") bin2 := as.NewBin("bin2", "value2") log.Printf("Put: namespace=%s set=%s key=%s bin1=%s value1=%s bin2=%s value2=%s", key.Namespace(), key.SetName(), key.Value(), bin1.Name, bin1.Value, bin2.Name, bin2.Value) client.PutBins(shared.WritePolicy, key, bin1, bin2) log.Printf("Get: namespace=%s set=%s key=%s", key.Namespace(), key.SetName(), key.Value()) record, err := client.Get(shared.Policy, key) shared.PanicOnError(err) if record == nil { panic(fmt.Errorf("Failed to get: namespace=%s set=%s key=%s", key.Namespace(), key.SetName(), key.Value())) } shared.ValidateBin(key, bin1, record) shared.ValidateBin(key, bin2, record) }
go
{ "resource": "" }
q10003
runGetHeaderExample
train
func runGetHeaderExample(client *as.Client) { key, _ := as.NewKey(*shared.Namespace, *shared.Set, "putgetkey") log.Printf("Get record header: namespace=%s set=%s key=%s", key.Namespace(), key.SetName(), key.Value()) record, err := client.GetHeader(shared.Policy, key) shared.PanicOnError(err) if record == nil { panic(fmt.Errorf("Failed to get: namespace=%s set=%s key=%s", key.Namespace(), key.SetName(), key.Value())) } // Generation should be greater than zero. Make sure it's populated. if record.Generation == 0 { panic(fmt.Errorf("Invalid record header: generation=%d expiration=%d", record.Generation, record.Expiration)) } log.Printf("Received: generation=%d expiration=%d (%s)\n", record.Generation, record.Expiration, time.Duration(record.Expiration)*time.Second) }
go
{ "resource": "" }
q10004
NewExecuteTask
train
func NewExecuteTask(cluster *Cluster, statement *Statement) *ExecuteTask { return &ExecuteTask{ baseTask: newTask(cluster), taskID: statement.TaskId, scan: statement.IsScan(), } }
go
{ "resource": "" }
q10005
NewBin
train
func NewBin(name string, value interface{}) *Bin { return &Bin{ Name: name, Value: NewValue(value), } }
go
{ "resource": "" }
q10006
dieIfError
train
func dieIfError(err error, cleanup ...func()) { if err != nil { log.Println("Error:") for _, cb := range cleanup { cb() } log.Fatalln(err.Error()) } return }
go
{ "resource": "" }
q10007
NewAtomicBool
train
func NewAtomicBool(value bool) *AtomicBool { var i int32 if value { i = 1 } return &AtomicBool{ val: i, } }
go
{ "resource": "" }
q10008
Set
train
func (ab *AtomicBool) Set(newVal bool) { var i int32 if newVal { i = 1 } atomic.StoreInt32(&(ab.val), int32(i)) }
go
{ "resource": "" }
q10009
Or
train
func (ab *AtomicBool) Or(newVal bool) bool { if !newVal { return ab.Get() } atomic.StoreInt32(&(ab.val), int32(1)) return true }
go
{ "resource": "" }
q10010
CompareAndToggle
train
func (ab *AtomicBool) CompareAndToggle(expect bool) bool { updated := 1 if expect { updated = 0 } res := atomic.CompareAndSwapInt32(&ab.val, int32(1-updated), int32(updated)) return res }
go
{ "resource": "" }
q10011
registerLuaStreamType
train
func registerLuaStreamType(L *lua.LState) { mt := L.NewTypeMetatable(luaLuaStreamTypeName) L.SetGlobal("stream", mt) // static attributes L.SetField(mt, "__call", L.NewFunction(newLuaStream)) L.SetField(mt, "read", L.NewFunction(luaStreamRead)) L.SetField(mt, "write", L.NewFunction(luaStreamWrite)) L.SetField(mt, "readable", L.NewFunction(luaStreamReadable)) L.SetField(mt, "writeable", L.NewFunction(luaStreamWriteable)) // methods L.SetFuncs(mt, map[string]lua.LGFunction{ "__tostring": luaStreamToString, }) L.SetMetatable(mt, mt) }
go
{ "resource": "" }
q10012
NewLuaStream
train
func NewLuaStream(L *lua.LState, stream chan interface{}) *lua.LUserData { luaStream := &LuaStream{s: stream} ud := L.NewUserData() ud.Value = luaStream L.SetMetatable(ud, L.GetTypeMetatable(luaLuaStreamTypeName)) return ud }
go
{ "resource": "" }
q10013
NewListPolicy
train
func NewListPolicy(order ListOrderType, flags int) *ListPolicy { return &ListPolicy{ attributes: order, flags: flags, } }
go
{ "resource": "" }
q10014
ListSetOrderOp
train
func ListSetOrderOp(binName string, listOrder ListOrderType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_SET_TYPE, IntegerValue(listOrder)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10015
ListAppendOp
train
func ListAppendOp(binName string, values ...interface{}) *Operation { if len(values) == 1 { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_APPEND, NewValue(values[0])}, encoder: listGenericOpEncoder} } return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_APPEND_ITEMS, ListValue(values)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10016
ListAppendWithPolicyOp
train
func ListAppendWithPolicyOp(policy *ListPolicy, binName string, values ...interface{}) *Operation { switch len(values) { case 1: return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_APPEND, NewValue(values[0]), IntegerValue(policy.attributes), IntegerValue(policy.flags)}, encoder: listGenericOpEncoder} default: return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_APPEND_ITEMS, ListValue(values), IntegerValue(policy.attributes), IntegerValue(policy.flags)}, encoder: listGenericOpEncoder} } }
go
{ "resource": "" }
q10017
ListInsertOp
train
func ListInsertOp(binName string, index int, values ...interface{}) *Operation { if len(values) == 1 { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_INSERT, IntegerValue(index), NewValue(values[0])}, encoder: listGenericOpEncoder} } return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_INSERT_ITEMS, IntegerValue(index), ListValue(values)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10018
ListPopOp
train
func ListPopOp(binName string, index int) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_POP, IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10019
ListPopRangeOp
train
func ListPopRangeOp(binName string, index int, count int) *Operation { if count == 1 { return ListPopOp(binName, index) } return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_POP_RANGE, IntegerValue(index), IntegerValue(count)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10020
ListPopRangeFromOp
train
func ListPopRangeFromOp(binName string, index int) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_POP_RANGE, IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10021
ListRemoveOp
train
func ListRemoveOp(binName string, index int) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE, IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10022
ListRemoveByValueOp
train
func ListRemoveByValueOp(binName string, value interface{}, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_BY_VALUE, IntegerValue(returnType), NewValue(value)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10023
ListRemoveByValueListOp
train
func ListRemoveByValueListOp(binName string, values []interface{}, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_BY_VALUE_LIST, IntegerValue(returnType), ListValue(values)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10024
ListRemoveRangeOp
train
func ListRemoveRangeOp(binName string, index int, count int) *Operation { if count == 1 { return ListRemoveOp(binName, index) } return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_RANGE, IntegerValue(index), IntegerValue(count)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10025
ListRemoveRangeFromOp
train
func ListRemoveRangeFromOp(binName string, index int) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_RANGE, IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10026
ListSetOp
train
func ListSetOp(binName string, index int, value interface{}) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_SET, IntegerValue(index), NewValue(value)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10027
ListTrimOp
train
func ListTrimOp(binName string, index int, count int) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_TRIM, IntegerValue(index), IntegerValue(count)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10028
ListClearOp
train
func ListClearOp(binName string) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_CLEAR}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10029
ListSizeOp
train
func ListSizeOp(binName string) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_SIZE}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10030
ListGetOp
train
func ListGetOp(binName string, index int) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET, IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10031
ListGetRangeOp
train
func ListGetRangeOp(binName string, index int, count int) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET_RANGE, IntegerValue(index), IntegerValue(count)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10032
ListSortOp
train
func ListSortOp(binName string, sortFlags int) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_SORT, IntegerValue(sortFlags)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10033
ListRemoveByIndexOp
train
func ListRemoveByIndexOp(binName string, index int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_BY_INDEX, IntegerValue(returnType), IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10034
ListRemoveByIndexRangeOp
train
func ListRemoveByIndexRangeOp(binName string, index, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_BY_INDEX_RANGE, IntegerValue(returnType), IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10035
ListRemoveByIndexRangeCountOp
train
func ListRemoveByIndexRangeCountOp(binName string, index, count int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_BY_INDEX_RANGE, IntegerValue(returnType), IntegerValue(index), IntegerValue(count)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10036
ListRemoveByRankOp
train
func ListRemoveByRankOp(binName string, rank int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_BY_RANK, IntegerValue(returnType), IntegerValue(rank)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10037
ListRemoveByRankRangeOp
train
func ListRemoveByRankRangeOp(binName string, rank int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_MODIFY, binName: binName, binValue: ListValue{_CDT_LIST_REMOVE_BY_RANK_RANGE, IntegerValue(returnType), IntegerValue(rank)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10038
ListGetByValueOp
train
func ListGetByValueOp(binName string, value interface{}, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET_BY_VALUE, IntegerValue(returnType), NewValue(value)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10039
ListGetByValueListOp
train
func ListGetByValueListOp(binName string, values []interface{}, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET_BY_VALUE_LIST, IntegerValue(returnType), ListValue(values)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10040
ListGetByIndexOp
train
func ListGetByIndexOp(binName string, index int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET_BY_INDEX, IntegerValue(returnType), IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10041
ListGetByIndexRangeOp
train
func ListGetByIndexRangeOp(binName string, index int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET_BY_INDEX_RANGE, IntegerValue(returnType), IntegerValue(index)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10042
ListGetByRankOp
train
func ListGetByRankOp(binName string, rank int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET_BY_RANK, IntegerValue(returnType), IntegerValue(rank)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10043
ListGetByRankRangeOp
train
func ListGetByRankRangeOp(binName string, rank int, returnType ListReturnType) *Operation { return &Operation{opType: _CDT_READ, binName: binName, binValue: ListValue{_CDT_LIST_GET_BY_RANK_RANGE, IntegerValue(returnType), IntegerValue(rank)}, encoder: listGenericOpEncoder} }
go
{ "resource": "" }
q10044
NewScanPolicy
train
func NewScanPolicy() *ScanPolicy { mp := *NewMultiPolicy() mp.TotalTimeout = 0 return &ScanPolicy{ MultiPolicy: mp, ScanPercent: 100, ConcurrentNodes: true, } }
go
{ "resource": "" }
q10045
NewRemoveTask
train
func NewRemoveTask(cluster *Cluster, packageName string) *RemoveTask { return &RemoveTask{ baseTask: newTask(cluster), packageName: packageName, } }
go
{ "resource": "" }
q10046
Get
train
func (bp *Pool) Get(params ...interface{}) interface{} { res := bp.pool.Poll() if res == nil || (bp.IsUsable != nil && !bp.IsUsable(res, params...)) { // not usable, so finalize if res != nil && bp.Finalize != nil { bp.Finalize(res) } if bp.New != nil { res = bp.New(params...) } } return res }
go
{ "resource": "" }
q10047
Put
train
func (bp *Pool) Put(obj interface{}) { finalize := true if bp.CanReturn == nil || bp.CanReturn(obj) { finalize = !bp.pool.Offer(obj) } if finalize && bp.Finalize != nil { bp.Finalize(obj) } }
go
{ "resource": "" }
q10048
NewClientPolicy
train
func NewClientPolicy() *ClientPolicy { return &ClientPolicy{ AuthMode: AuthModeInternal, Timeout: 30 * time.Second, IdleTimeout: defaultIdleTimeout, LoginTimeout: 10 * time.Second, ConnectionQueueSize: 256, OpeningConnectionThreshold: 0, FailIfNotConnected: true, TendInterval: time.Second, LimitConnectionsToQueueSize: true, IgnoreOtherSubnetAliases: false, } }
go
{ "resource": "" }
q10049
newConnection
train
func newConnection(address string, timeout time.Duration) (*Connection, error) { newConn := &Connection{dataBuffer: make([]byte, DefaultBufferSize)} runtime.SetFinalizer(newConn, connectionFinalizer) // don't wait indefinitely if timeout == 0 { timeout = 5 * time.Second } conn, err := net.DialTimeout("tcp", address, timeout) if err != nil { Logger.Error("Connection to address `" + address + "` failed to establish with error: " + err.Error()) return nil, errToTimeoutErr(nil, err) } newConn.conn = conn // set timeout at the last possible moment if err := newConn.SetTimeout(time.Now().Add(timeout), timeout); err != nil { newConn.Close() return nil, err } return newConn, nil }
go
{ "resource": "" }
q10050
NewConnection
train
func NewConnection(policy *ClientPolicy, host *Host) (*Connection, error) { address := net.JoinHostPort(host.Name, strconv.Itoa(host.Port)) conn, err := newConnection(address, policy.Timeout) if err != nil { return nil, err } if policy.TlsConfig == nil { return conn, nil } // Use version dependent clone function to clone the config tlsConfig := cloneTLSConfig(policy.TlsConfig) tlsConfig.ServerName = host.TLSName sconn := tls.Client(conn.conn, tlsConfig) if err := sconn.Handshake(); err != nil { sconn.Close() return nil, err } if host.TLSName != "" && !tlsConfig.InsecureSkipVerify { if err := sconn.VerifyHostname(host.TLSName); err != nil { sconn.Close() Logger.Error("Connection to address `" + address + "` failed to establish with error: " + err.Error()) return nil, errToTimeoutErr(nil, err) } } conn.conn = sconn return conn, nil }
go
{ "resource": "" }
q10051
Write
train
func (ctn *Connection) Write(buf []byte) (total int, err error) { // make sure all bytes are written // Don't worry about the loop, timeout has been set elsewhere length := len(buf) for total < length { var r int if err = ctn.updateDeadline(); err != nil { break } r, err = ctn.conn.Write(buf[total:]) total += r if err != nil { break } } // If all bytes are written, ignore any potential error // The error will bubble up on the next network io if it matters. if total == len(buf) { return total, nil } if ctn.node != nil { atomic.AddInt64(&ctn.node.stats.ConnectionsFailed, 1) } ctn.Close() return total, errToTimeoutErr(ctn, err) }
go
{ "resource": "" }
q10052
updateDeadline
train
func (ctn *Connection) updateDeadline() error { now := time.Now() var socketDeadline time.Time if ctn.deadline.IsZero() { if ctn.socketTimeout > 0 { socketDeadline = now.Add(ctn.socketTimeout) } } else { if now.After(ctn.deadline) { return NewAerospikeError(TIMEOUT) } if ctn.socketTimeout == 0 { socketDeadline = ctn.deadline } else { tDeadline := now.Add(ctn.socketTimeout) if tDeadline.After(ctn.deadline) { socketDeadline = ctn.deadline } else { socketDeadline = tDeadline } } // floor to a millisecond to avoid too short timeouts if socketDeadline.Sub(now) < time.Millisecond { socketDeadline = now.Add(time.Millisecond) } } if err := ctn.conn.SetDeadline(socketDeadline); err != nil { if ctn.node != nil { atomic.AddInt64(&ctn.node.stats.ConnectionsFailed, 1) } return err } return nil }
go
{ "resource": "" }
q10053
SetTimeout
train
func (ctn *Connection) SetTimeout(deadline time.Time, socketTimeout time.Duration) error { ctn.deadline = deadline ctn.socketTimeout = socketTimeout return nil }
go
{ "resource": "" }
q10054
authenticateFast
train
func (ctn *Connection) authenticateFast(user string, hashedPass []byte) error { // need to authenticate if len(user) > 0 { command := newLoginCommand(ctn.dataBuffer) if err := command.authenticateInternal(ctn, user, hashedPass); err != nil { if ctn.node != nil { atomic.AddInt64(&ctn.node.stats.ConnectionsFailed, 1) } // Socket not authenticated. Do not put back into pool. ctn.Close() return err } } return nil }
go
{ "resource": "" }
q10055
login
train
func (ctn *Connection) login(sessionToken []byte) error { // need to authenticate if ctn.node.cluster.clientPolicy.RequiresAuthentication() { policy := &ctn.node.cluster.clientPolicy switch policy.AuthMode { case AuthModeExternal: var err error command := newLoginCommand(ctn.dataBuffer) if sessionToken == nil { err = command.login(&ctn.node.cluster.clientPolicy, ctn, ctn.node.cluster.Password()) } else { err = command.authenticateViaToken(&ctn.node.cluster.clientPolicy, ctn, sessionToken) } if err != nil { if ctn.node != nil { atomic.AddInt64(&ctn.node.stats.ConnectionsFailed, 1) } // Socket not authenticated. Do not put back into pool. ctn.Close() return err } if command.SessionToken != nil { ctn.node._sessionToken.Store(command.SessionToken) ctn.node._sessionExpiration.Store(command.SessionExpiration) } return nil case AuthModeInternal: return ctn.authenticateFast(policy.User, ctn.node.cluster.Password()) } } return nil }
go
{ "resource": "" }
q10056
isIdle
train
func (ctn *Connection) isIdle() bool { return ctn.idleTimeout > 0 && !time.Now().Before(ctn.idleDeadline) }
go
{ "resource": "" }
q10057
refresh
train
func (ctn *Connection) refresh() { ctn.idleDeadline = time.Now().Add(ctn.idleTimeout) }
go
{ "resource": "" }
q10058
GetObject
train
func (clnt *Client) GetObject(policy *BasePolicy, key *Key, obj interface{}) error { policy = clnt.getUsablePolicy(policy) rval := reflect.ValueOf(obj) binNames := objectMappings.getFields(rval.Type()) command := newReadCommand(clnt.cluster, policy, key, binNames) command.object = &rval return command.Execute() }
go
{ "resource": "" }
q10059
BatchGetObjects
train
func (clnt *Client) BatchGetObjects(policy *BatchPolicy, keys []*Key, objects []interface{}) (found []bool, err error) { policy = clnt.getUsableBatchPolicy(policy) // check the size of key and objects if (len(keys) != len(objects)) || (len(keys) == 0) { return nil, errors.New("Wrong Number of arguments to BatchGetObject. Number of keys and objects do not match.") } binSet := map[string]struct{}{} objectsVal := make([]*reflect.Value, len(objects)) for i := range objects { rval := reflect.ValueOf(objects[i]) objectsVal[i] = &rval for _, bn := range objectMappings.getFields(rval.Type()) { binSet[bn] = struct{}{} } } binNames := make([]string, 0, len(binSet)) for binName := range binSet { binNames = append(binNames, binName) } objectsFound := make([]bool, len(keys)) cmd := newBatchCommandGet(nil, nil, nil, policy, keys, binNames, nil, _INFO1_READ) cmd.objects = objectsVal cmd.objectsFound = objectsFound if err = clnt.batchExecute(policy, keys, cmd); err != nil { return nil, err } return objectsFound, nil }
go
{ "resource": "" }
q10060
ScanAllObjects
train
func (clnt *Client) ScanAllObjects(apolicy *ScanPolicy, objChan interface{}, namespace string, setName string, binNames ...string) (*Recordset, error) { policy := *clnt.getUsableScanPolicy(apolicy) nodes := clnt.cluster.GetNodes() if len(nodes) == 0 { return nil, NewAerospikeError(SERVER_NOT_AVAILABLE, "Scan failed because cluster is empty.") } // result recordset taskID := uint64(xornd.Int64()) res := &Recordset{ objectset: *newObjectset(reflect.ValueOf(objChan), len(nodes), taskID), } // the whole call should be wrapped in a goroutine if policy.ConcurrentNodes { for _, node := range nodes { go func(node *Node) { // Errors are handled inside the command itself clnt.scanNodeObjects(&policy, node, res, namespace, setName, taskID, binNames...) }(node) } } else { // scan nodes one by one go func() { for _, node := range nodes { // Errors are handled inside the command itself clnt.scanNodeObjects(&policy, node, res, namespace, setName, taskID, binNames...) } }() } return res, nil }
go
{ "resource": "" }
q10061
ScanNodeObjects
train
func (clnt *Client) ScanNodeObjects(apolicy *ScanPolicy, node *Node, objChan interface{}, namespace string, setName string, binNames ...string) (*Recordset, error) { policy := *clnt.getUsableScanPolicy(apolicy) // results channel must be async for performance taskID := uint64(xornd.Int64()) res := &Recordset{ objectset: *newObjectset(reflect.ValueOf(objChan), 1, taskID), } go clnt.scanNodeObjects(&policy, node, res, namespace, setName, taskID, binNames...) return res, nil }
go
{ "resource": "" }
q10062
scanNodeObjects
train
func (clnt *Client) scanNodeObjects(policy *ScanPolicy, node *Node, recordset *Recordset, namespace string, setName string, taskID uint64, binNames ...string) error { command := newScanObjectsCommand(node, policy, namespace, setName, binNames, recordset, taskID) return command.Execute() }
go
{ "resource": "" }
q10063
QueryObjects
train
func (clnt *Client) QueryObjects(policy *QueryPolicy, statement *Statement, objChan interface{}) (*Recordset, error) { policy = clnt.getUsableQueryPolicy(policy) nodes := clnt.cluster.GetNodes() if len(nodes) == 0 { return nil, NewAerospikeError(SERVER_NOT_AVAILABLE, "Query failed because cluster is empty.") } // results channel must be async for performance recSet := &Recordset{ objectset: *newObjectset(reflect.ValueOf(objChan), len(nodes), statement.TaskId), } // the whole call sho // results channel must be async for performance for _, node := range nodes { // copy policies to avoid race conditions newPolicy := *policy command := newQueryObjectsCommand(node, &newPolicy, statement, recSet) go func() { // Do not send the error to the channel; it is already handled in the Execute method command.Execute() }() } return recSet, nil }
go
{ "resource": "" }
q10064
QueryNodeObjects
train
func (clnt *Client) QueryNodeObjects(policy *QueryPolicy, node *Node, statement *Statement, objChan interface{}) (*Recordset, error) { policy = clnt.getUsableQueryPolicy(policy) // results channel must be async for performance recSet := &Recordset{ objectset: *newObjectset(reflect.ValueOf(objChan), 1, statement.TaskId), } // copy policies to avoid race conditions newPolicy := *policy command := newQueryRecordCommand(node, &newPolicy, statement, recSet) go func() { command.Execute() }() return recSet, nil }
go
{ "resource": "" }
q10065
NewMapPolicy
train
func NewMapPolicy(order mapOrderType, writeMode *mapWriteMode) *MapPolicy { return &MapPolicy{ attributes: order, flags: MapWriteFlagsDefault, itemCommand: writeMode.itemCommand, itemsCommand: writeMode.itemsCommand, } }
go
{ "resource": "" }
q10066
NewMapPolicyWithFlags
train
func NewMapPolicyWithFlags(order mapOrderType, flags int) *MapPolicy { return &MapPolicy{ attributes: order, flags: flags, itemCommand: MapWriteMode.UPDATE.itemCommand, itemsCommand: MapWriteMode.UPDATE.itemsCommand, } }
go
{ "resource": "" }
q10067
MapPutItemsOp
train
func MapPutItemsOp(policy *MapPolicy, binName string, amap map[interface{}]interface{}) *Operation { if policy.flags != 0 { ops := _CDT_MAP_PUT_ITEMS // Replace doesn't allow map attributes because it does not create on non-existing key. return &Operation{ opType: _MAP_MODIFY, opSubType: &ops, binName: binName, binValue: ListValue([]interface{}{amap, IntegerValue(policy.attributes), IntegerValue(policy.flags)}), encoder: newCDTCreateOperationEncoder, } } if policy.itemsCommand == int(_CDT_MAP_REPLACE_ITEMS) { // Replace doesn't allow map attributes because it does not create on non-existing key. return &Operation{ opType: _MAP_MODIFY, opSubType: &policy.itemsCommand, binName: binName, binValue: ListValue([]interface{}{MapValue(amap)}), encoder: newCDTCreateOperationEncoder, } } return &Operation{ opType: _MAP_MODIFY, opSubType: &policy.itemsCommand, binName: binName, binValue: ListValue([]interface{}{MapValue(amap), IntegerValue(policy.attributes)}), encoder: newCDTCreateOperationEncoder, } }
go
{ "resource": "" }
q10068
MapIncrementOp
train
func MapIncrementOp(policy *MapPolicy, binName string, key interface{}, incr interface{}) *Operation { return newCDTCreateOperationValues2(_CDT_MAP_INCREMENT, policy.attributes, binName, key, incr) }
go
{ "resource": "" }
q10069
MapDecrementOp
train
func MapDecrementOp(policy *MapPolicy, binName string, key interface{}, decr interface{}) *Operation { return newCDTCreateOperationValues2(_CDT_MAP_DECREMENT, policy.attributes, binName, key, decr) }
go
{ "resource": "" }
q10070
MapRemoveByKeyOp
train
func MapRemoveByKeyOp(binName string, key interface{}, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_REMOVE_BY_KEY, _MAP_MODIFY, binName, key, returnType) }
go
{ "resource": "" }
q10071
MapRemoveByKeyListOp
train
func MapRemoveByKeyListOp(binName string, keys []interface{}, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_REMOVE_KEY_LIST, _MAP_MODIFY, binName, keys, returnType) }
go
{ "resource": "" }
q10072
MapRemoveByValueOp
train
func MapRemoveByValueOp(binName string, value interface{}, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_REMOVE_BY_VALUE, _MAP_MODIFY, binName, value, returnType) }
go
{ "resource": "" }
q10073
MapRemoveByValueListOp
train
func MapRemoveByValueListOp(binName string, values []interface{}, returnType mapReturnType) *Operation { return newCDTCreateOperationValuesN(_CDT_MAP_REMOVE_VALUE_LIST, _MAP_MODIFY, binName, values, returnType) }
go
{ "resource": "" }
q10074
MapRemoveByIndexOp
train
func MapRemoveByIndexOp(binName string, index int, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_REMOVE_BY_INDEX, _MAP_MODIFY, binName, index, returnType) }
go
{ "resource": "" }
q10075
MapRemoveByIndexRangeOp
train
func MapRemoveByIndexRangeOp(binName string, index int, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_REMOVE_BY_INDEX_RANGE, _MAP_MODIFY, binName, index, returnType) }
go
{ "resource": "" }
q10076
MapRemoveByIndexRangeCountOp
train
func MapRemoveByIndexRangeCountOp(binName string, index int, count int, returnType mapReturnType) *Operation { return newCDTCreateOperationIndexCount(_CDT_MAP_REMOVE_BY_INDEX_RANGE, _MAP_MODIFY, binName, index, count, returnType) }
go
{ "resource": "" }
q10077
MapRemoveByRankOp
train
func MapRemoveByRankOp(binName string, rank int, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_REMOVE_BY_RANK, _MAP_MODIFY, binName, rank, returnType) }
go
{ "resource": "" }
q10078
MapRemoveByRankRangeOp
train
func MapRemoveByRankRangeOp(binName string, rank int, returnType mapReturnType) *Operation { return newCDTCreateOperationIndex(_CDT_MAP_REMOVE_BY_RANK_RANGE, _MAP_MODIFY, binName, rank, returnType) }
go
{ "resource": "" }
q10079
MapRemoveByRankRangeCountOp
train
func MapRemoveByRankRangeCountOp(binName string, rank int, count int, returnType mapReturnType) *Operation { return newCDTCreateOperationIndexCount(_CDT_MAP_REMOVE_BY_RANK_RANGE, _MAP_MODIFY, binName, rank, count, returnType) }
go
{ "resource": "" }
q10080
MapGetByKeyOp
train
func MapGetByKeyOp(binName string, key interface{}, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_GET_BY_KEY, _MAP_READ, binName, key, returnType) }
go
{ "resource": "" }
q10081
MapGetByKeyListOp
train
func MapGetByKeyListOp(binName string, keys []interface{}, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_GET_BY_KEY_LIST, _MAP_READ, binName, keys, returnType) }
go
{ "resource": "" }
q10082
MapGetByValueOp
train
func MapGetByValueOp(binName string, value interface{}, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_GET_BY_VALUE, _MAP_READ, binName, value, returnType) }
go
{ "resource": "" }
q10083
MapGetByIndexOp
train
func MapGetByIndexOp(binName string, index int, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_GET_BY_INDEX, _MAP_READ, binName, index, returnType) }
go
{ "resource": "" }
q10084
MapGetByIndexRangeOp
train
func MapGetByIndexRangeOp(binName string, index int, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_GET_BY_INDEX_RANGE, _MAP_READ, binName, index, returnType) }
go
{ "resource": "" }
q10085
MapGetByIndexRangeCountOp
train
func MapGetByIndexRangeCountOp(binName string, index int, count int, returnType mapReturnType) *Operation { return newCDTCreateOperationIndexCount(_CDT_MAP_GET_BY_INDEX_RANGE, _MAP_READ, binName, index, count, returnType) }
go
{ "resource": "" }
q10086
MapGetByRankOp
train
func MapGetByRankOp(binName string, rank int, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_GET_BY_RANK, _MAP_READ, binName, rank, returnType) }
go
{ "resource": "" }
q10087
MapGetByRankRangeOp
train
func MapGetByRankRangeOp(binName string, rank int, returnType mapReturnType) *Operation { return newCDTCreateOperationValue1(_CDT_MAP_GET_BY_RANK_RANGE, _MAP_READ, binName, rank, returnType) }
go
{ "resource": "" }
q10088
MapGetByRankRangeCountOp
train
func MapGetByRankRangeCountOp(binName string, rank int, count int, returnType mapReturnType) *Operation { return newCDTCreateOperationIndexCount(_CDT_MAP_GET_BY_RANK_RANGE, _MAP_READ, binName, rank, count, returnType) }
go
{ "resource": "" }
q10089
NewAtomicQueue
train
func NewAtomicQueue(size int) *AtomicQueue { if size <= 0 { panic("Queue size cannot be less than 1") } return &AtomicQueue{ wrapped: false, data: make([]interface{}, uint32(size)), size: uint32(size), } }
go
{ "resource": "" }
q10090
Offer
train
func (q *AtomicQueue) Offer(obj interface{}) bool { q.mutex.Lock() // make sure queue is not full if q.tail == q.head && q.wrapped { q.mutex.Unlock() return false } if q.head+1 == q.size { q.wrapped = true } q.head = (q.head + 1) % q.size q.data[q.head] = obj q.mutex.Unlock() return true }
go
{ "resource": "" }
q10091
Poll
train
func (q *AtomicQueue) Poll() (res interface{}) { q.mutex.Lock() // if queue is not empty if q.wrapped || (q.tail != q.head) { if q.tail+1 == q.size { q.wrapped = false } q.tail = (q.tail + 1) % q.size res = q.data[q.tail] } q.mutex.Unlock() return res }
go
{ "resource": "" }
q10092
NewDropIndexTask
train
func NewDropIndexTask(cluster *Cluster, namespace string, indexName string) *DropIndexTask { return &DropIndexTask{ baseTask: newTask(cluster), namespace: namespace, indexName: indexName, } }
go
{ "resource": "" }
q10093
NewBlobValue
train
func NewBlobValue(object AerospikeBlob) BytesValue { buf, err := object.EncodeBlob() if err != nil { panic(err) } return NewBytesValue(buf) }
go
{ "resource": "" }
q10094
Set
train
func (sv *SyncVal) Set(val interface{}) { sv.lock.Lock() sv.val = val sv.lock.Unlock() }
go
{ "resource": "" }
q10095
Get
train
func (sv *SyncVal) Get() interface{} { sv.lock.RLock() val := sv.val sv.lock.RUnlock() return val }
go
{ "resource": "" }
q10096
GetSyncedVia
train
func (sv *SyncVal) GetSyncedVia(f func(interface{}) (interface{}, error)) (interface{}, error) { sv.lock.RLock() defer sv.lock.RUnlock() val, err := f(sv.val) return val, err }
go
{ "resource": "" }
q10097
Update
train
func (sv *SyncVal) Update(f func(interface{}) (interface{}, error)) error { sv.lock.Lock() defer sv.lock.Unlock() val, err := f(sv.val) if err == nil { sv.val = val } return err }
go
{ "resource": "" }
q10098
NewAtomicInt
train
func NewAtomicInt(value int) *AtomicInt { v := int64(value) return &AtomicInt{ val: v, } }
go
{ "resource": "" }
q10099
AddAndGet
train
func (ai *AtomicInt) AddAndGet(delta int) int { res := int(atomic.AddInt64(&ai.val, int64(delta))) return res }
go
{ "resource": "" }