Пример #1
0
 /// <summary>
 /// Initialize large list operator.
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="policy">generic configuration parameters, pass in null for defaults</param>
 /// <param name="key">unique record identifier</param>
 /// <param name="binName">bin name</param>
 public LargeList(AerospikeClient client, WritePolicy policy, Key key, string binName)
 {
     this.client = client;
     this.policy = policy;
     this.key = key;
     this.binName = Value.Get(binName);
 }
Пример #2
0
        public void SetUdf(WritePolicy policy, Key key, string packageName, string functionName, Value[] args)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);
            int predSize   = 0;

            if (policy.predExp != null)
            {
                predSize = EstimatePredExp(policy.predExp);
                fieldCount++;
            }
            byte[] argBytes = Packer.Pack(args);
            fieldCount += EstimateUdfSize(packageName, functionName, argBytes);

            SizeBuffer();
            WriteHeader(policy, 0, Command.INFO2_WRITE, fieldCount, 0);
            WriteKey(policy, key);

            if (policy.predExp != null)
            {
                WritePredExp(policy.predExp, predSize);
            }
            WriteField(packageName, FieldType.UDF_PACKAGE_NAME);
            WriteField(functionName, FieldType.UDF_FUNCTION);
            WriteField(argBytes, FieldType.UDF_ARGLIST);
            End();
        }
Пример #3
0
        public void Replace()
        {
            Key key = new Key(args.ns, args.set, "replacekey");
            Bin bin1 = new Bin("bin1", "value1");
            Bin bin2 = new Bin("bin2", "value2");
            Bin bin3 = new Bin("bin3", "value3");

            client.Put(null, key, bin1, bin2);

            WritePolicy policy = new WritePolicy();
            policy.recordExistsAction = RecordExistsAction.REPLACE;
            client.Put(policy, key, bin3);

            Record record = client.Get(null, key);
            AssertRecordFound(key, record);

            if (record.GetValue(bin1.name) != null)
            {
                Assert.Fail(bin1.name + " found when it should have been deleted.");
            }

            if (record.GetValue(bin2.name) != null)
            {
                Assert.Fail(bin2.name + " found when it should have been deleted.");
            }
            AssertBinEqual(key, record, bin3);
        }
Пример #4
0
 /// <summary>
 /// Initialize large list operator.
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="policy">generic configuration parameters, pass in null for defaults</param>
 /// <param name="key">unique record identifier</param>
 /// <param name="binName">bin name</param>
 public LargeList(AerospikeClient client, WritePolicy policy, Key key, string binName)
 {
     this.client  = client;
     this.policy  = policy;
     this.key     = key;
     this.binName = Value.Get(binName);
 }
 /// <summary>
 /// Copy client policy from another client policy.
 /// </summary>
 public ClientPolicy(ClientPolicy other)
 {
     this.user                 = other.user;
     this.password             = other.password;
     this.clusterName          = other.clusterName;
     this.authMode             = other.authMode;
     this.timeout              = other.timeout;
     this.loginTimeout         = other.loginTimeout;
     this.maxConnsPerNode      = other.maxConnsPerNode;
     this.connPoolsPerNode     = other.connPoolsPerNode;
     this.maxSocketIdle        = other.maxSocketIdle;
     this.tendInterval         = other.tendInterval;
     this.failIfNotConnected   = other.failIfNotConnected;
     this.readPolicyDefault    = new Policy(other.readPolicyDefault);
     this.writePolicyDefault   = new WritePolicy(other.writePolicyDefault);
     this.scanPolicyDefault    = new ScanPolicy(other.scanPolicyDefault);
     this.queryPolicyDefault   = new QueryPolicy(other.queryPolicyDefault);
     this.batchPolicyDefault   = new BatchPolicy(other.batchPolicyDefault);
     this.infoPolicyDefault    = new InfoPolicy(other.infoPolicyDefault);
     this.tlsPolicy            = (other.tlsPolicy != null) ? new TlsPolicy(other.tlsPolicy) : null;
     this.ipMap                = other.ipMap;
     this.useServicesAlternate = other.useServicesAlternate;
     this.rackAware            = other.rackAware;
     this.rackId               = other.rackId;
 }
        public static void Main(string[] args)
        {
            var client = Connect();
            var policy = new Policy();
            var writePolicy = new WritePolicy();
            var batchPolicy = new BatchPolicy();

            //NOTE: adjust the timeout value depending on your demo machine
            writePolicy.timeout = 1000;
            var key = new Key("test", "myset", "mykey");

            WriteSingleValue(client, writePolicy, key);
            CheckKeyExists(client, policy, key);
            AddSingleValue(client, writePolicy);
            WriteMultipleValues(client, writePolicy, key);
            WriteValueWithTtl(client);

            ReadAllValuesForKey(client, policy, key);
            ReadSomeValuesForKey(client, policy, key);

            DeleteValue(client, writePolicy, key);
            DeleteRecord(client, writePolicy, key);

            AddRecords(client, writePolicy);
            BatchReadRecords(client, batchPolicy);

            MultiOps(client, writePolicy, key);

            client.Close();
        }
Пример #7
0
 public AsyncOperate(AsyncOperate other)
     : base(other)
 {
     this.writePolicy = other.writePolicy;
     this.operations  = other.operations;
     this.args        = other.args;
 }
Пример #8
0
        public void SetOperate(WritePolicy policy, Key key, Operation[] operations, OperateArgs args)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);
            int predSize   = 0;

            if (policy.predExp != null)
            {
                predSize = EstimatePredExp(policy.predExp);
                fieldCount++;
            }
            dataOffset += args.size;
            SizeBuffer();

            WriteHeader(policy, args.readAttr, args.writeAttr, fieldCount, operations.Length);
            WriteKey(policy, key);

            if (policy.predExp != null)
            {
                WritePredExp(policy.predExp, predSize);
            }

            foreach (Operation operation in operations)
            {
                WriteOperation(operation);
            }
            End();
        }
Пример #9
0
        public void SetWrite(WritePolicy policy, Operation.Type operation, Key key, Bin[] bins)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);
            int predSize   = 0;

            if (policy.predExp != null)
            {
                predSize = EstimatePredExp(policy.predExp);
                fieldCount++;
            }

            foreach (Bin bin in bins)
            {
                EstimateOperationSize(bin);
            }
            SizeBuffer();
            WriteHeader(policy, 0, Command.INFO2_WRITE, fieldCount, bins.Length);
            WriteKey(policy, key);

            if (policy.predExp != null)
            {
                WritePredExp(policy.predExp, predSize);
            }

            foreach (Bin bin in bins)
            {
                WriteOperation(bin, operation);
            }
            End();
        }
Пример #10
0
 public ExecuteCommand(WritePolicy writePolicy, Key key, string packageName, string functionName, Value[] args)
     : base(key)
 {
     this.writePolicy  = writePolicy;
     this.packageName  = packageName;
     this.functionName = functionName;
     this.args         = args;
 }
Пример #11
0
 // UDF constructor.
 public AsyncRead(AsyncCluster cluster, WritePolicy policy, Key key)
     : base(cluster, policy)
 {
     this.listener  = null;
     this.key       = key;
     this.binNames  = null;
     this.partition = Partition.Write(cluster, policy, key);
 }
 public ExecuteCommand(Cluster cluster, WritePolicy writePolicy, Key key, string packageName, string functionName, Value[] args)
     : base(cluster, writePolicy, key, null)
 {
     this.writePolicy = writePolicy;
     this.packageName = packageName;
     this.functionName = functionName;
     this.args = args;
 }
Пример #13
0
 public ExecuteCommand(Cluster cluster, WritePolicy writePolicy, Key key, string packageName, string functionName, Value[] args)
     : base(cluster, writePolicy, key, null)
 {
     this.writePolicy  = writePolicy;
     this.packageName  = packageName;
     this.functionName = functionName;
     this.args         = args;
 }
Пример #14
0
 /// <summary>
 /// Initialize large set operator.
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="policy">generic configuration parameters, pass in null for defaults</param>
 /// <param name="key">unique record identifier</param>
 /// <param name="binName">bin name</param>
 /// <param name="createModule">Lua function name that initializes list configuration parameters, pass null for default set</param>
 public LargeSet(AerospikeClient client, WritePolicy policy, Key key, string binName, string createModule)
 {
     this.client = client;
     this.policy = policy;
     this.key = key;
     this.binName = Value.Get(binName);
     this.createModule = Value.Get(createModule);
 }
Пример #15
0
 /// <summary>
 /// Initialize large set operator.
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="policy">generic configuration parameters, pass in null for defaults</param>
 /// <param name="key">unique record identifier</param>
 /// <param name="binName">bin name</param>
 /// <param name="createModule">Lua function name that initializes list configuration parameters, pass null for default set</param>
 public LargeSet(AerospikeClient client, WritePolicy policy, Key key, string binName, string createModule)
 {
     this.client       = client;
     this.policy       = policy;
     this.key          = key;
     this.binName      = Value.Get(binName);
     this.createModule = Value.Get(createModule);
 }
 public AsyncExecute(AsyncExecute other)
     : base(other)
 {
     this.writePolicy     = other.writePolicy;
     this.executeListener = other.executeListener;
     this.packageName     = other.packageName;
     this.functionName    = other.functionName;
     this.args            = other.args;
 }
 public AsyncExecute(AsyncCluster cluster, WritePolicy writePolicy, ExecuteListener listener, Key key, string packageName, string functionName, Value[] args)
     : base(cluster, writePolicy, null, key, null)
 {
     this.writePolicy     = writePolicy;
     this.executeListener = listener;
     this.packageName     = packageName;
     this.functionName    = functionName;
     this.args            = args;
 }
Пример #18
0
 public AsyncExecute(AsyncCluster cluster, WritePolicy writePolicy, ExecuteListener listener, Key key, string packageName, string functionName, Value[] args)
     : base(cluster, writePolicy, null, key, null)
 {
     this.writePolicy = writePolicy;
     this.executeListener = listener;
     this.packageName = packageName;
     this.functionName = functionName;
     this.args = args;
 }
 private static void AddSingleValue(AerospikeClient client,
         WritePolicy writePolicy)
 {
     var newKey = new Key("test", "myAddSet", "myAddKey");
     var counter = new Bin("mybin", 1);
     client.Add(writePolicy, newKey, counter);
     Console.WriteLine("Wrote this additional value (or bin):  " + newKey);
     Console.WriteLine("");
 }
Пример #20
0
        public void SetOperate(WritePolicy policy, Key key, Operation[] operations)
        {
            Begin();
            int  fieldCount = EstimateKeySize(policy, key);
            int  readAttr   = 0;
            int  writeAttr  = 0;
            bool readBin    = false;
            bool readHeader = false;

            foreach (Operation operation in operations)
            {
                switch (operation.type)
                {
                case Operation.Type.CDT_READ:
                case Operation.Type.READ:
                    readAttr |= Command.INFO1_READ;

                    // Read all bins if no bin is specified.
                    if (operation.binName == null)
                    {
                        readAttr |= Command.INFO1_GET_ALL;
                    }
                    readBin = true;
                    break;

                case Operation.Type.READ_HEADER:
                    readAttr  |= Command.INFO1_READ;
                    readHeader = true;
                    break;

                default:
                    writeAttr = Command.INFO2_WRITE;
                    break;
                }
                EstimateOperationSize(operation);
            }
            SizeBuffer();

            if (readHeader && !readBin)
            {
                readAttr |= Command.INFO1_NOBINDATA;
            }

            if (writeAttr != 0 && policy.respondAllOps)
            {
                writeAttr |= Command.INFO2_RESPOND_ALL_OPS;
            }

            WriteHeader(policy, readAttr, writeAttr, fieldCount, operations.Length);
            WriteKey(policy, key);

            foreach (Operation operation in operations)
            {
                WriteOperation(operation);
            }
            End();
        }
Пример #21
0
        public void SetDelete(WritePolicy policy, Key key)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);

            SizeBuffer();
            WriteHeader(policy, 0, Command.INFO2_WRITE | Command.INFO2_DELETE, fieldCount, 0);
            WriteKey(policy, key);
            End();
        }
Пример #22
0
 public Program(AerospikeClient c)
 {
     this.client = c;
     this.epoch = DateTime.Now;
     this.updatePolicy = new WritePolicy ();
     this.updatePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
     this.updatePolicy.recordExistsAction = RecordExistsAction.UPDATE_ONLY;
     this.createPolicy = new WritePolicy ();
     this.createPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY;
 }
Пример #23
0
        public void SetTouch(WritePolicy policy, Key key)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);

            EstimateOperationSize();
            SizeBuffer();
            WriteHeader(policy, 0, Command.INFO2_WRITE, fieldCount, 1);
            WriteKey(policy, key);
            WriteOperation(Operation.Type.TOUCH);
            End();
        }
 private static void AddRecords(AerospikeClient client,
         WritePolicy writePolicy)
 {
     const int size = 1024;
     for (var i = 0; i < size; i++)
     {
         var key = new Key("test", "myset", (i + 1));
         client.Put(writePolicy, key, new Bin("dots", i + " dots"));
     }
     Console.WriteLine("Added " + size + " Records");
     Console.WriteLine("");
 }
Пример #25
0
        /// <summary>
        /// Demonstrate touch command.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "touchkey");
            Bin bin = new Bin(args.GetBinName("touchbin"), "touchvalue");

            console.Info("Create record with 2 second expiration.");
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            console.Info("Touch same record with 5 second expiration.");
            writePolicy.expiration = 5;
            Record record = client.Operate(writePolicy, key, Operation.Touch(), Operation.GetHeader());

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, null));
            }

            if (record.expiration == 0)
            {
                throw new Exception(string.Format("Failed to get record expiration: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            console.Info("Sleep 3 seconds.");
            Thread.Sleep(3000);

            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            console.Info("Success. Record still exists.");
            console.Info("Sleep 4 seconds.");
            Thread.Sleep(4000);

            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                console.Info("Success. Record expired as expected.");
            }
            else
            {
                console.Error("Found record when it should have expired.");
            }
        }
Пример #26
0
        public static void WriteRecords(TestContext testContext)
        {
            WritePolicy policy = new WritePolicy();
            policy.expiration = 2592000;

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, valuePrefix + i);

                client.Put(policy, key, bin);
            }
        }
Пример #27
0
        public void createTweet()
        {
            Console.WriteLine("\n********** Create Tweet **********\n");

            Record userRecord = null;
            Key userKey = null;
            Key tweetKey = null;

            // Get username
            string username;
            Console.WriteLine("\nEnter username:"******"test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    int nextTweetCount = int.Parse(userRecord.GetValue("tweetcount").ToString()) + 1;

                    // Get tweet
                    string tweet;
                    Console.WriteLine("Enter tweet for " + username + ":");
                    tweet = Console.ReadLine();

                    // Write record
                    WritePolicy wPolicy = new WritePolicy();
                    wPolicy.recordExistsAction = RecordExistsAction.UPDATE;

                    // Create timestamp to store along with the tweet so we can query, index and report on it
                    long ts = getTimeStamp();

                    tweetKey = new Key("test", "tweets", username + ":" + nextTweetCount);
                    Bin bin1 = new Bin("tweet", tweet);
                    Bin bin2 = new Bin("ts", ts);
                    Bin bin3 = new Bin("username", username);

                    client.Put(wPolicy, tweetKey, bin1, bin2, bin3);
                    Console.WriteLine("\nINFO: Tweet record created!");

                    // Update tweet count and last tweet'd timestamp in the user record
                    updateUser(client, userKey, wPolicy, ts, nextTweetCount);
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
        }
Пример #28
0
        /// <summary>
        /// Write and twice read a bin value, demonstrating record expiration.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "expirekey");
            Bin bin = new Bin(args.GetBinName("expirebin"), "expirevalue");

            console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expiration=2",
                key.ns, key.setName, key.userKey, bin.name, bin.value);

            // Specify that record expires 2 seconds after it's written.
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            // Read the record before it expires, showing it's there.
            console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);

            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            object received = record.GetValue(bin.name);
            string expected = bin.value.ToString();

            if (received.Equals(expected))
            {
                console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                throw new Exception(string.Format("Expire mismatch: Expected {0}. Received {1}.", expected, received));
            }

            // Read the record after it expires, showing it's gone.
            console.Info("Sleeping for 3 seconds ...");
            Thread.Sleep(3 * 1000);
            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                console.Info("Expiry successful. Record not found.");
            }
            else
            {
                console.Error("Found record when it should have expired.");
            }
        }
        public void Generation()
        {
            Key key = new Key(args.ns, args.set, "genkey");
            string binName = args.GetBinName("genbin");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Set some values for the same record.
            Bin bin = new Bin(binName, "genvalue1");

            client.Put(null, key, bin);

            bin = new Bin(binName, "genvalue2");

            client.Put(null, key, bin);

            // Retrieve record and its generation count.
            Record record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin);

            // Set record and fail if it's not the expected generation.
            bin = new Bin(binName, "genvalue3");

            WritePolicy writePolicy = new WritePolicy();
            writePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
            writePolicy.generation = record.generation;
            client.Put(writePolicy, key, bin);

            // Set record with invalid generation and check results .
            bin = new Bin(binName, "genvalue4");
            writePolicy.generation = 9999;

            try
            {
                client.Put(writePolicy, key, bin);
                Assert.Fail("Should have received generation error instead of success.");
            }
            catch (AerospikeException ae)
            {
                if (ae.Result != ResultCode.GENERATION_ERROR)
                {
                    Assert.Fail("Unexpected return code: namespace=" + key.ns + " set=" + key.setName + " key=" + key.userKey + " bin=" + bin.name + " value=" + bin.value + " code=" + ae.Result);
                }
            }

            // Verify results.
            record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin.name, "genvalue3");
        }
        public void SetArgs(Cluster cluster, WritePolicy writePolicy, OperateArgs args)
        {
            this.writePolicy = writePolicy;
            this.args        = args;

            if (args.hasWrite)
            {
                partition = Partition.Write(cluster, writePolicy, key);
            }
            else
            {
                partition = Partition.Read(cluster, writePolicy, key);
            }
        }
 protected override void WriteRecord(WritePolicy policy, Key key, Bin bin)
 {
     if (shared.writeLatency != null)
     {
         Stopwatch watch = Stopwatch.StartNew();
         client.Put(policy, key, bin);
         double elapsed = watch.Elapsed.TotalMilliseconds;
         OnWriteSuccess(elapsed);
     }
     else
     {
         client.Put(policy, key, bin);
         OnWriteSuccess();
     }
 }
Пример #32
0
        private void RunReplaceExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "replacekey");
            Bin bin1 = new Bin("bin1", "value1");
            Bin bin2 = new Bin("bin2", "value2");
            Bin bin3 = new Bin("bin3", "value3");

            console.Info("Put: namespace={0} set={1} key={2} bin1={3} value1={4} bin2={5} value2={6}",
                key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);

            client.Put(args.writePolicy, key, bin1, bin2);

            console.Info("Replace with: namespace={0} set={1} key={2} bin={3} value={4}",
                key.ns, key.setName, key.userKey, bin3.name, bin3.value);

            WritePolicy policy = new WritePolicy();
            policy.recordExistsAction = RecordExistsAction.REPLACE;
            client.Put(policy, key, bin3);

            console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);

            Record record = client.Get(args.policy, key);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            if (record.GetValue(bin1.name) == null)
            {
                console.Info(bin1.name + " was deleted as expected.");
            }
            else
            {
                console.Error(bin1.name + " found when it should have been deleted.");
            }

            if (record.GetValue(bin2.name) == null)
            {
                console.Info(bin2.name + " was deleted as expected.");
            }
            else
            {
                console.Error(bin2.name + " found when it should have been deleted.");
            }
            ValidateBin(key, bin3, record);
        }
Пример #33
0
        public void SetArgs(AsyncCluster cluster, WritePolicy writePolicy, OperateArgs args)
        {
            base.policy      = writePolicy;
            this.writePolicy = writePolicy;
            this.args        = args;

            if (args.hasWrite)
            {
                base.partition = Partition.Write(cluster, writePolicy, key);
            }
            else
            {
                base.isRead    = true;
                base.partition = Partition.Read(cluster, writePolicy, key);
            }
        }
Пример #34
0
        public static void Prepare(TestContext testContext)
        {
            Policy policy = new Policy();
            policy.timeout = 0; // Do not timeout on index create.
            IndexTask itask = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC);
            itask.Wait();

            WritePolicy writePolicy = new WritePolicy();
            writePolicy.sendKey = true;

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, i);
                client.Put(writePolicy, key, bin);
            }
        }
Пример #35
0
        public void SetOperate(WritePolicy policy, Key key, Operation[] operations, OperateArgs args)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);

            dataOffset += args.size;
            SizeBuffer();

            WriteHeader(policy, args.readAttr, args.writeAttr, fieldCount, operations.Length);
            WriteKey(policy, key);

            foreach (Operation operation in operations)
            {
                WriteOperation(operation);
            }
            End();
        }
        protected override void WriteRecord(WritePolicy policy, Key key, Bin bin)
        {
            // If timeout occurred, yield thread to back off throttle.
            // Fail counters are reset every second.
            if (shared.writeTimeoutCount > 0)
            {
                Thread.Yield();
            }

            if (shared.writeLatency != null)
            {
                client.Put(policy, new LatencyWriteHandler(this, key, bin), key, bin);
            }
            else
            {
                client.Put(policy, new WriteHandler(this, key, bin), key, bin);
            }
        }
Пример #37
0
        public void Expire()
        {
            Key key = new Key(args.ns, args.set, "expirekey ");
            Bin bin = new Bin(binName, "expirevalue");

            // Specify that record expires 2 seconds after it's written.
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            // Read the record before it expires, showing it is there.
            Record record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin);

            // Read the record after it expires, showing it's gone.
            Util.Sleep(3 * 1000);
            record = client.Get(null, key, bin.name);
            Assert.IsNull(record);
        }
        private void ServerSideExists(AerospikeClient client, WritePolicy policy, Key key, Bin bin, int search, bool expected)
        {
            long lexists = (long)client.Execute(policy, key, "record_example", "valueExists", Value.Get(bin.name), Value.Get(search));
            bool exists = (lexists != 0);

            if (expected && exists)
            {
                console.Info("Value found as expected.");
                return;
            }

            if (!expected && !exists)
            {
                console.Info("Value not found as expected.");
                return;
            }

            console.Error("Data mismatch. Expected " + expected + " Received " + exists);
        }
Пример #39
0
        public void SetDelete(WritePolicy policy, Key key)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);
            int predSize   = 0;

            if (policy.predExp != null)
            {
                predSize = EstimatePredExp(policy.predExp);
                fieldCount++;
            }
            SizeBuffer();
            WriteHeader(policy, 0, Command.INFO2_WRITE | Command.INFO2_DELETE, fieldCount, 0);
            WriteKey(policy, key);

            if (policy.predExp != null)
            {
                WritePredExp(policy.predExp, predSize);
            }
            End();
        }
Пример #40
0
        public void NoExpire()
        {
            Key key = new Key(args.ns, args.set, "expirekey");
            Bin bin = new Bin(binName, "noexpirevalue");

            // Specify that record NEVER expires.
            // The "Never Expire" value is -1, or 0xFFFFFFFF.
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = -1;
            client.Put(writePolicy, key, bin);

            // Read the record, showing it is there.
            Record record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin);

            // Read this Record after the Default Expiration, showing it is still there.
            // We should have set the Namespace TTL at 5 sec.
            Util.Sleep(10 * 1000);
            record = client.Get(null, key, bin.name);
            Assert.IsNotNull(record);
        }
Пример #41
0
        /// <summary>
        /// Initialize large stack operator.
        /// </summary>
        /// <param name="client">client</param>
        /// <param name="policy">generic configuration parameters, pass in null for defaults</param>
        /// <param name="key">unique record identifier</param>
        /// <param name="binName">bin name</param>
        /// <param name="headBinName">Bin name for the head counter, null for default</param>
        public LargeStack(AerospikeClient client, WritePolicy policy, Key key, string binName, string headBinName)
        {
            this.client = client;
            this.policy = policy;
            this.key = key;
            this.lockKey = new Key(this.key.ns, LOCK_SET_NAME, this.key.digest);
            this.binName = binName;
            if (headBinName == null)
                this.headBinName = DEFAULT_HEAD_BIN_NAME;
            else
                this.headBinName = headBinName;

            if (this.policy == null){
                this.lockPolicy = new WritePolicy();
            } else {
                this.lockPolicy = new WritePolicy(this.policy);
            }
            if (this.policy != null)
                this.batchPolicy = new BatchPolicy(policy);
            else
                this.batchPolicy = new BatchPolicy(this.client.batchPolicyDefault);
        }
        public static void WriteRecords(TestContext testContext)
        {
            sendKeys = new Key[size];

            for (int i = 0; i < size; i++)
            {
                sendKeys[i] = new Key(args.ns, args.set, keyPrefix + (i + 1));
            }

            AsyncMonitor monitor = new AsyncMonitor();
            WriteHandler handler = new WriteHandler(monitor, size);

            WritePolicy policy = new WritePolicy();
            policy.expiration = 2592000;

            for (int i = 1; i <= size; i++)
            {
                Key key = sendKeys[i - 1];
                Bin bin = new Bin(binName, valuePrefix + i);
                client.Put(policy, handler, key, bin);
            }
            monitor.WaitTillComplete();
        }
Пример #43
0
        private static void AerospikeWriteMethod(User user)
        {
            using (var client = new AC.AerospikeClient(Config.DOCKER_MACHINE_IP, 3000))
            {
                if (!client.Connected)
                {
                    Console.WriteLine("Aerospike ERROR: Connection failed!");
                    return;
                }

                var wPolicy = new AC.WritePolicy
                {
                    recordExistsAction = AC.RecordExistsAction.UPDATE
                };

                var key     = new AC.Key("test", "users", user.Id);
                var binId   = new AC.Bin("id", user.Id);
                var binName = new AC.Bin("name", user.Name);
                var binAge  = new AC.Bin("age", user.Age);

                client.Put(wPolicy, key, binId, binName, binAge);
            }
        }
Пример #44
0
        public void SetTouch(WritePolicy policy, Key key)
        {
            Begin();
            int fieldCount = EstimateKeySize(policy, key);
            int predSize   = 0;

            if (policy.predExp != null)
            {
                predSize = EstimatePredExp(policy.predExp);
                fieldCount++;
            }
            EstimateOperationSize();
            SizeBuffer();
            WriteHeader(policy, 0, Command.INFO2_WRITE, fieldCount, 1);
            WriteKey(policy, key);

            if (policy.predExp != null)
            {
                WritePredExp(policy.predExp, predSize);
            }
            WriteOperation(Operation.Type.TOUCH);
            End();
        }
Пример #45
0
        public void Touch()
        {
            Key key = new Key(args.ns, args.set, "touchkey");
            Bin bin = new Bin(args.GetBinName("touchbin"), "touchvalue");

            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            writePolicy.expiration = 5;
            Record record = client.Operate(writePolicy, key, Operation.Touch(), Operation.GetHeader());
            AssertRecordFound(key, record);
            Assert.AreNotEqual(0, record.expiration);

            Util.Sleep(3000);

            record = client.Get(null, key, bin.name);
            AssertRecordFound(key, record);

            Util.Sleep(4000);

            record = client.Get(null, key, bin.name);
            Assert.IsNull(record);
        }
Пример #46
0
        public void ReplaceOnly()
        {
            Key key = new Key(args.ns, args.set, "replaceonlykey");
            Bin bin = new Bin("bin", "value");

            // Delete record if it already exists.
            client.Delete(null, key);

            try
            {
                WritePolicy policy = new WritePolicy();
                policy.recordExistsAction = RecordExistsAction.REPLACE_ONLY;
                client.Put(policy, key, bin);

                Assert.Fail("Failure. This command should have resulted in an error.");
            }
            catch (AerospikeException ae)
            {
                if (ae.Result != ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    throw ae;
                }
            }
        }
        /// <summary>
        /// Header write for write operations.
        /// </summary>
        protected internal void WriteHeader(WritePolicy policy, int readAttr, int writeAttr, int fieldCount, int operationCount)
        {
            // Set flags.
            int generation = 0;
            int infoAttr   = 0;

            switch (policy.recordExistsAction)
            {
            case RecordExistsAction.UPDATE:
                break;

            case RecordExistsAction.UPDATE_ONLY:
                infoAttr |= Command.INFO3_UPDATE_ONLY;
                break;

            case RecordExistsAction.REPLACE:
                infoAttr |= Command.INFO3_CREATE_OR_REPLACE;
                break;

            case RecordExistsAction.REPLACE_ONLY:
                infoAttr |= Command.INFO3_REPLACE_ONLY;
                break;

            case RecordExistsAction.CREATE_ONLY:
                writeAttr |= Command.INFO2_CREATE_ONLY;
                break;
            }

            switch (policy.generationPolicy)
            {
            case GenerationPolicy.NONE:
                break;

            case GenerationPolicy.EXPECT_GEN_EQUAL:
                generation = policy.generation;
                writeAttr |= Command.INFO2_GENERATION;
                break;

            case GenerationPolicy.EXPECT_GEN_GT:
                generation = policy.generation;
                writeAttr |= Command.INFO2_GENERATION_GT;
                break;
            }

            if (policy.commitLevel == CommitLevel.COMMIT_MASTER)
            {
                infoAttr |= Command.INFO3_COMMIT_MASTER;
            }

            if (policy.consistencyLevel == ConsistencyLevel.CONSISTENCY_ALL)
            {
                readAttr |= Command.INFO1_CONSISTENCY_ALL;
            }

            // Write all header data except total size which must be written last.
            dataBuffer[8]  = MSG_REMAINING_HEADER_SIZE;            // Message header length.
            dataBuffer[9]  = (byte)readAttr;
            dataBuffer[10] = (byte)writeAttr;
            dataBuffer[11] = (byte)infoAttr;
            dataBuffer[12] = 0;             // unused
            dataBuffer[13] = 0;             // clear the result code
            ByteUtil.IntToBytes((uint)generation, dataBuffer, 14);
            ByteUtil.IntToBytes((uint)policy.expiration, dataBuffer, 18);

            // Initialize timeout. It will be written later.
            dataBuffer[22] = 0;
            dataBuffer[23] = 0;
            dataBuffer[24] = 0;
            dataBuffer[25] = 0;

            ByteUtil.ShortToBytes((ushort)fieldCount, dataBuffer, 26);
            ByteUtil.ShortToBytes((ushort)operationCount, dataBuffer, 28);
            dataOffset = MSG_TOTAL_HEADER_SIZE;
        }
Пример #48
0
 private void updateUser(AerospikeClient client, Key userKey, WritePolicy policy, long ts, int tweetCount)
 {
     // Update tweet count and last tweet'd timestamp in the user record
     client.Put(policy, userKey, new Bin("tweetcount", tweetCount), new Bin("lasttweeted", ts));
     Console.WriteLine("INFO: The tweet count now is: " + tweetCount);
 }
Пример #49
0
        public void createTweets()
        {
            string[] randomTweets = { "For just $1 you get a half price download of half of the song and listen to it just once.", "People tell me my body looks like a melted candle", "Come on movie! Make it start!", "Byaaaayy", "Please, please, win! Meow, meow, meow!", "Put. A. Bird. On. It.", "A weekend wasted is a weekend well spent", "Would you like to super spike your meal?", "We have a mean no-no-bring-bag up here on aisle two.", "SEEK: See, Every, EVERY, Kind... of spot", "We can order that for you. It will take a year to get there.", "If you are pregnant, have a soda.", "Hear that snap? Hear that clap?", "Follow me and I may follow you", "Which is the best cafe in Portland? Discuss...", "Portland Coffee is for closers!", "Lets get this party started!", "How about them portland blazers!", "You got school'd, yo", "I love animals", "I love my dog", "What's up Portland", "Which is the best cafe in Portland? Discuss...", "I dont always tweet, but when I do it is on Tweetaspike" };
            Random rnd1 = new Random();
            Random rnd2 = new Random();
            Random rnd3 = new Random();
            Key userKey;
            Record userRecord;
            int totalUsers = 10000;
            int maxTweets = 20;
            string username;
            long ts = 0;
            WritePolicy wPolicy = new WritePolicy();
            wPolicy.recordExistsAction = RecordExistsAction.UPDATE;

            Console.WriteLine("\nCreate up to " + maxTweets + " tweets each for " + totalUsers + " users. Press any key to continue...");
            Console.ReadLine();

            for (int j = 0; j < totalUsers; j++)
            {
                // Check if user record exists
                username = "******" + rnd3.Next(1, 100000);
                userKey = new Key("test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    // create up to maxTweets random tweets for this user
                    int totalTweets = rnd1.Next(1, (maxTweets + 1));
                    for (int k = 1; k <= totalTweets; k++)
                    {
                        // Create timestamp to store along with the tweet so we can query, index and report on it
                        ts = getTimeStamp();
                        Key tweetKey = new Key("test", "tweets", username + ":" + k);
                        Bin bin1 = new Bin("tweet", randomTweets[rnd2.Next(1, randomTweets.Length)]);
                        Bin bin2 = new Bin("ts", ts);
                        Bin bin3 = new Bin("username", username);

                        client.Put(wPolicy, tweetKey, bin1, bin2, bin3);
                    }
                    if (totalTweets > 0)
                    {
                        // Update tweet count and last tweet'd timestamp in the user record
                        client.Put(wPolicy, userKey, new Bin("tweetcount", totalTweets), new Bin("lasttweeted", ts));
                        //Console.WriteLine("INFO: The tweet count now is: " + totalTweets);
                    }
                    Console.WriteLine("Wrote " + totalTweets + " tweets for " + username + "!");
                }
            }
            Console.WriteLine("\nDone creating up to " + maxTweets + " tweets each for " + totalUsers + " users!");
        }
Пример #50
0
 protected internal Arguments()
 {
     this.writePolicy = new WritePolicy();
     this.policy = new Policy();
 }
Пример #51
0
        /// <summary>
        /// Header write for write operations.
        /// </summary>
        private void WriteHeader(WritePolicy policy, int readAttr, int writeAttr, int fieldCount, int operationCount)
        {
            // Set flags.
            int generation = 0;
            int infoAttr   = 0;

            switch (policy.recordExistsAction)
            {
            case RecordExistsAction.UPDATE:
                break;

            case RecordExistsAction.UPDATE_ONLY:
                infoAttr |= Command.INFO3_UPDATE_ONLY;
                break;

            case RecordExistsAction.REPLACE:
                infoAttr |= Command.INFO3_CREATE_OR_REPLACE;
                break;

            case RecordExistsAction.REPLACE_ONLY:
                infoAttr |= Command.INFO3_REPLACE_ONLY;
                break;

            case RecordExistsAction.CREATE_ONLY:
                writeAttr |= Command.INFO2_CREATE_ONLY;
                break;
            }

            switch (policy.generationPolicy)
            {
            case GenerationPolicy.NONE:
                break;

            case GenerationPolicy.EXPECT_GEN_EQUAL:
                generation = policy.generation;
                writeAttr |= Command.INFO2_GENERATION;
                break;

            case GenerationPolicy.EXPECT_GEN_GT:
                generation = policy.generation;
                writeAttr |= Command.INFO2_GENERATION_GT;
                break;
            }

            if (policy.commitLevel == CommitLevel.COMMIT_MASTER)
            {
                infoAttr |= Command.INFO3_COMMIT_MASTER;
            }

            if (policy.linearizeRead)
            {
                infoAttr |= Command.INFO3_LINEARIZE_READ;
            }

            if (policy.consistencyLevel == ConsistencyLevel.CONSISTENCY_ALL)
            {
                readAttr |= Command.INFO1_CONSISTENCY_ALL;
            }

            if (policy.durableDelete)
            {
                writeAttr |= Command.INFO2_DURABLE_DELETE;
            }

            dataOffset += 8;

            // Write all header data except total size which must be written last.
            dataBuffer[dataOffset++] = MSG_REMAINING_HEADER_SIZE;             // Message header length.
            dataBuffer[dataOffset++] = (byte)readAttr;
            dataBuffer[dataOffset++] = (byte)writeAttr;
            dataBuffer[dataOffset++] = (byte)infoAttr;
            dataBuffer[dataOffset++] = 0;             // unused
            dataBuffer[dataOffset++] = 0;             // clear the result code
            dataOffset += ByteUtil.IntToBytes((uint)generation, dataBuffer, dataOffset);
            dataOffset += ByteUtil.IntToBytes((uint)policy.expiration, dataBuffer, dataOffset);
            dataOffset += ByteUtil.IntToBytes((uint)policy.totalTimeout, dataBuffer, dataOffset);
            dataOffset += ByteUtil.ShortToBytes((ushort)fieldCount, dataBuffer, dataOffset);
            dataOffset += ByteUtil.ShortToBytes((ushort)operationCount, dataBuffer, dataOffset);
        }
Пример #52
0
 public AsyncOperate(AsyncCluster cluster, WritePolicy policy, RecordListener listener, Key key, Operation[] operations)
     : base(cluster, policy, listener, key, null)
 {
     this.writePolicy = policy;
     this.operations  = operations;
 }
 public OperateCommand(Cluster cluster, WritePolicy policy, Key key, Operation[] operations)
     : base(cluster, policy, key, null)
 {
     this.writePolicy = policy;
     this.operations  = operations;
 }
        public void OperateList7()
        {
            // Test null values.
            Key key = new Key(args.ns, args.set, "oplkey7");

            client.Delete(null, key);

            WritePolicy policy = new WritePolicy();
            policy.respondAllOps = true;

            IList itemList = new List<Value>();
            itemList.Add(Value.Get("s11"));
            itemList.Add(Value.AsNull);
            itemList.Add(Value.Get("s3333333"));

            Record record = client.Operate(null, key,
                ListOperation.AppendItems(binName, itemList),
                ListOperation.Get(binName, 0),
                ListOperation.Get(binName, 1),
                ListOperation.Get(binName, 2)
                );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int i = 0;

            long size = (long)results[i++];
            Assert.AreEqual(3, size);

            string str = (string)results[i++];
            Assert.AreEqual("s11", str);

            str = (string)results[i++];
            Assert.IsNull(str);

            str = (string)results[i++];
            Assert.AreEqual("s3333333", str);
        }
        public void OperateList6()
        {
            // Test clear.
            Key key = new Key(args.ns, args.set, "oplkey6");

            client.Delete(null, key);

            WritePolicy policy = new WritePolicy();
            policy.respondAllOps = true;

            IList itemList = new List<Value>();
            itemList.Add(Value.Get("s11"));
            itemList.Add(Value.Get("s22222"));
            itemList.Add(Value.Get("s3333333"));
            itemList.Add(Value.Get("s4444444444"));
            itemList.Add(Value.Get("s5555555555555555"));

            Record record = client.Operate(policy, key,
                Operation.Put(new Bin("otherbin", 11)),
                Operation.Get("otherbin"),
                ListOperation.AppendItems(binName, itemList),
                ListOperation.Clear(binName),
                ListOperation.Size(binName)
                );

            AssertRecordFound(key, record);

            IList list = record.GetList("otherbin");
            Assert.AreEqual(2, list.Count);
            Assert.IsNull(list[0]);
            Assert.AreEqual(11, (long)(long)list[1]);

            list = record.GetList(binName);

            long size = (long)list[0];
            Assert.AreEqual(5, size);

            // clear() does not return value by default, but we set respondAllOps, so it returns null.
            Assert.IsNull(list[1]);

            size = (long)list[2];
            Assert.AreEqual(0, size);
        }
Пример #56
0
 public void SetArgs(WritePolicy writePolicy, OperateArgs args)
 {
     base.policy      = writePolicy;
     this.writePolicy = writePolicy;
     this.args        = args;
 }