public static void AssertRecordFound(Key key, Record record)
 {
     if (record == null)
     {
         Assert.Fail("Failed to get: namespace=" + args.ns + " set=" + args.set + " key=" + key.userKey);
     }
 }
        protected void printRecord(Key key, Record record)
        {
            Console.WriteLine("Key");
            if (key == null)
            {
                Console.WriteLine("\tkey == null");
            }
            else
            {
                Console.WriteLine(String.Format("\tNamespace: {0}", key.ns));
                Console.WriteLine(String.Format("\t      Set: {0}", key.setName));
                Console.WriteLine(String.Format("\t      Key: {0}", key.userKey));
                Console.WriteLine(String.Format("\t   Digest: {0}", key.digest.ToString()));
            }
            Console.WriteLine("Record");
            if (record == null)
            {
                Console.WriteLine("\trecord == null");
            }
            else
            {
                Console.WriteLine(String.Format("\tGeneration: {0}", record.generation));
                Console.WriteLine(String.Format("\tExpiration: {0}", record.expiration));
                Console.WriteLine(String.Format("\t       TTL: {0}", record.TimeToLive));
                Console.WriteLine("Bins");

                foreach (KeyValuePair<string, Object> entry in record.bins)
                {
                    Console.WriteLine(String.Format("\t{0} = {1}", entry.Key, entry.Value.ToString()));
                }
            }
        }
        public void ScanCallback(Key key, Record record)
        {
            int count = Interlocked.Increment(ref recordCount);

            if ((count % 10000) == 0)
            {
                console.Info("Records " + count);
            }
        }
            public void OnRecord(Key key, Record record)
            {
                parent.recordCount++;

                if ((parent.recordCount % 10000) == 0)
                {
                    ;
                }
            }
        public static void AssertBinEqual(Key key, Record record, String binName, Object expected)
        {
            AssertRecordFound(key, record);

            object received = record.GetValue(binName);

            if (received == null || !received.Equals(expected))
            {
                Assert.Fail("Data mismatch: Expected " + expected + ". Received " + received);
            }
        }
        public static void AssertBinEqual(Key key, Record record, String binName, int expected)
        {
            AssertRecordFound(key, record);

            int received = record.GetInt(binName);

            if (received != expected)
            {
                Assert.Fail("Data mismatch: Expected " + expected + ". Received " + received);
            }
        }
        public void ScanCallback(Key key, Record record)
        {
            Metrics metrics;

            if (!setMap.TryGetValue(key.setName, out metrics))
            {
                metrics = new Metrics();
            }
            metrics.count++;
            metrics.total++;
            setMap[key.setName] = metrics;
        }
 private void ValidateBin(Key key, Record record, string binName, object expected, object received)
 {
     if (received != null && received.Equals(expected))
     {
         console.Info("Bin matched: namespace={0} set={1} key={2} bin={3} value={4} generation={5} expiration={6}",
             key.ns, key.setName, key.userKey, binName, received, record.generation, record.expiration);
     }
     else
     {
         console.Error("Bin mismatch: Expected {0}. Received {1}.", expected, received);
     }
 }
        public bool AssertBinEqual(Key key, Record record, string binName, object expected)
        {
            if (!AssertRecordFound(key, record))
            {
                return false;
            }

            object received = record.GetValue(binName);

            if (received == null || !received.Equals(expected))
            {
                monitor.SetError("Data mismatch: Expected " + expected + ". Received " + received);
            }
            return true;
        }
Example #10
0
        protected internal override void ParseRow(Key key)
        {
            int offset  = batch.offsets[index++];
            Key keyOrig = keys[offset];

            if (Util.ByteArrayEquals(key.digest, keyOrig.digest))
            {
                if (resultCode == 0)
                {
                    Record record = ParseRecord();
                    listener.OnRecord(keyOrig, record);
                }
                else
                {
                    listener.OnRecord(keyOrig, null);
                }
            }
            else
            {
                throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + index + ',' + offset);
            }
        }
        protected internal override void ParseResult()
        {
            int resultCode = dataBuffer[dataOffset + 5];

            if (resultCode == 0)
            {
                int generation = ByteUtil.BytesToInt(dataBuffer, dataOffset + 6);
                int expiration = ByteUtil.BytesToInt(dataBuffer, dataOffset + 10);

                record = new Record(null, generation, expiration);
            }
            else
            {
                if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    record = null;
                }
                else
                {
                    throw new AerospikeException(resultCode);
                }
            }
        }
        private void ValidateBin(Key key, Bin bin, Record record)
        {
            object received = record.GetValue(bin.name);
            string expected = bin.value.ToString();

            if (received != null && received.Equals(expected))
            {
                console.Info("Bin matched: namespace={0} set={1} key={2} bin={3} value={4} generation={5} expiration={6}",
                    key.ns, key.setName, key.userKey, bin.name, received, record.generation, record.expiration);
            }
            else
            {
                console.Error("Put/Get mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
 public void OnRecord(Key key, Record record)
 {
     int result = record.GetInt(binName);
     parent.console.Info("Result: " + result);
 }
 public void OnRecord(Key key, Record record)
 {
     int result = record.GetInt(binName);
     parent.AssertBetween(26, 34, result);
     Interlocked.Increment(ref count);
 }
            public virtual void OnSuccess(Key[] keys, Record[] records)
            {
                for (int i = 0; i < records.Length; i++)
                {
                    Key key = keys[i];
                    Record record = records[i];
                    Log.Level level = Log.Level.ERROR;
                    object value = null;

                    if (record != null)
                    {
                        level = Log.Level.INFO;
                        value = record.GetValue(parent.binName);
                    }
                    parent.console.Write(level, "Record: namespace={0} set={1} key={2} bin={3} value={4}",
                        key.ns, key.setName, key.userKey, parent.binName, value);
                }

                if (records.Length != BatchSize)
                {
                    parent.console.Error("Record size mismatch. Expected {0}. Received {1}.",
                        BatchSize, records.Length);
                }
                parent.TaskComplete();
            }
        public AsyncBatchGetArrayDirect(
			AsyncMultiExecutor parent,
			AsyncCluster cluster,
			AsyncNode node,
			BatchNode.BatchNamespace batch,
			Policy policy,
			Key[] keys,
			string[] binNames,
			Record[] records,
			int readAttr
		)
            : base(parent, cluster, node, false)
        {
            this.batch = batch;
            this.policy = policy;
            this.keys = keys;
            this.binNames = binNames;
            this.records = records;
            this.readAttr = readAttr;
        }
 public void scanTweetsCallback(Key key, Record record)
 {
     Console.WriteLine(record.GetValue("tweet"));
 }
 public virtual void OnSuccess(Key key, Record record)
 {
     parent.ValidateBin(key, bin, record);
     parent.NotifyCompleted();
 }
            public virtual void OnSuccess(Key[] keys, Record[] records)
            {
                for (int i = 0; i < records.Length; i++)
                {
                    Key key = keys[i];
                    Record record = records[i];
                    Log.Level level = Log.Level.ERROR;
                    int generation = 0;
                    int expiration = 0;

                    if (record != null && (record.generation > 0 || record.expiration > 0))
                    {
                        level = Log.Level.INFO;
                        generation = record.generation;
                        expiration = record.expiration;
                    }
                    parent.console.Write(level, "Record: namespace={0} set={1} key={2} generation={3} expiration={4}",
                        key.ns, key.setName, key.userKey, generation, expiration);
                }

                if (records.Length != BatchSize)
                {
                    parent.console.Error("Record size mismatch. Expected {0}. Received {1}.", BatchSize, records.Length);
                }
                parent.TaskComplete();
            }
 public void OnSuccess(Key k, Record record)
 {
     double elapsed = watch.Elapsed.TotalMilliseconds;
     parent.OnReadSuccess(elapsed);
 }
            public virtual void OnRecord(Key key, Record record)
            {
                Log.Level level = Log.Level.ERROR;
                object value = null;

                if (record != null)
                {
                    level = Log.Level.INFO;
                    value = record.GetValue(parent.binName);
                }
                parent.console.Write(level, "Record: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, ByteUtil.BytesToHexString(key.digest), parent.binName, value);
            }
 public void OnRecord(Key key, Record record)
 {
     if (parent.AssertRecordFound(key, record))
     {
         Object value = record.GetValue(binName);
         parent.AssertNotNull(value);
     }
 }
            public void OnSuccess(Key[] keys, Record[] records)
            {
                if (parent.AssertEquals(size, records.Length))
                {
                    for (int i = 0; i < records.Length; i++)
                    {
                        Record record = records[i];

                        if (!parent.AssertRecordFound(keys[i], record))
                        {
                            break;
                        }

                        if (!parent.AssertGreaterThanZero(record.generation))
                        {
                            break;
                        }

                        if (!parent.AssertGreaterThanZero(record.expiration))
                        {
                            break;
                        }
                    }
                }
                parent.NotifyCompleted();
            }
 public void OnSuccess(Key[] keys, Record[] records)
 {
     if (parent.AssertEquals(size, records.Length))
     {
         for (int i = 0; i < records.Length; i++)
         {
             if (!parent.AssertBinEqual(keys[i], records[i], binName, valuePrefix + (i + 1)))
             {
                 break;
             }
         }
     }
     parent.NotifyCompleted();
 }
        private static void ExecuteNode(BatchNode batchNode, BatchPolicy policy, Key[] keys, bool[] existsArray, Record[] records, string[] binNames, int readAttr)
        {
            if (batchNode.node.UseNewBatch(policy))
            {
                // New batch
                if (records != null)
                {
                    MultiCommand command = new BatchGetArrayCommand(batchNode, policy, keys, binNames, records, readAttr);
                    command.Execute();
                }
                else
                {
                    MultiCommand command = new BatchExistsArrayCommand(batchNode, policy, keys, existsArray);
                    command.Execute();
                }
            }
            else
            {
                // Old batch only allows one namespace per call.
                batchNode.SplitByNamespace(keys);

                foreach (BatchNode.BatchNamespace batchNamespace in batchNode.batchNamespaces)
                {
                    if (records != null)
                    {
                        MultiCommand command = new BatchGetArrayDirect(batchNode.node, batchNamespace, policy, keys, binNames, records, readAttr);
                        command.Execute();
                    }
                    else
                    {
                        MultiCommand command = new BatchExistsArrayDirect(batchNode.node, batchNamespace, policy, keys, existsArray);
                        command.Execute();
                    }
                }
            }
        }
 public Position(BinaryReader reader, Record record)
 {
     // Read ticker and discard, because the joined record also contains the ticker.
     reader.ReadString();
     qty = reader.ReadDouble();
     security = new Security(record);
 }
        public static void Execute(Cluster cluster, BatchPolicy policy, Key[] keys, bool[] existsArray, Record[] records, string[] binNames, int readAttr)
        {
            if (keys.Length == 0)
            {
                return;
            }

            if (policy.allowProleReads)
            {
                // Send all requests to a single node chosen in round-robin fashion in this transaction thread.
                Node node = cluster.GetRandomNode();
                BatchNode batchNode = new BatchNode(node, keys);
                ExecuteNode(batchNode, policy, keys, existsArray, records, binNames, readAttr);
                return;
            }

            List<BatchNode> batchNodes = BatchNode.GenerateList(cluster, policy, keys);

            if (policy.maxConcurrentThreads == 1 || batchNodes.Count <= 1)
            {
                // Run batch requests sequentially in same thread.
                foreach (BatchNode batchNode in batchNodes)
                {
                    ExecuteNode(batchNode, policy, keys, existsArray, records, binNames, readAttr);
                }
            }
            else
            {
                // Run batch requests in parallel in separate threads.
                //
                // Multiple threads write to the record/exists array, so one might think that
                // volatile or memory barriers are needed on the write threads and this read thread.
                // This should not be necessary here because it happens in Executor which does a
                // volatile write (Interlocked.Increment(ref completedCount)) at the end of write threads
                // and a synchronized WaitTillComplete() in this thread.
                Executor executor = new Executor(batchNodes.Count * 2);

                // Initialize threads.
                foreach (BatchNode batchNode in batchNodes)
                {
                    if (batchNode.node.UseNewBatch(policy))
                    {
                        // New batch
                        if (records != null)
                        {
                            MultiCommand command = new BatchGetArrayCommand(batchNode, policy, keys, binNames, records, readAttr);
                            executor.AddCommand(command);
                        }
                        else
                        {
                            MultiCommand command = new BatchExistsArrayCommand(batchNode, policy, keys, existsArray);
                            executor.AddCommand(command);
                        }
                    }
                    else
                    {
                        // There may be multiple threads for a single node because the
                        // wire protocol only allows one namespace per command.  Multiple namespaces
                        // require multiple threads per node.
                        batchNode.SplitByNamespace(keys);

                        foreach (BatchNode.BatchNamespace batchNamespace in batchNode.batchNamespaces)
                        {
                            if (records != null)
                            {
                                MultiCommand command = new BatchGetArrayDirect(batchNode.node, batchNamespace, policy, keys, binNames, records, readAttr);
                                executor.AddCommand(command);
                            }
                            else
                            {
                                MultiCommand command = new BatchExistsArrayDirect(batchNode.node, batchNamespace, policy, keys, existsArray);
                                executor.AddCommand(command);
                            }
                        }
                    }
                }
                executor.Execute(policy.maxConcurrentThreads);
            }
        }
 public Security(Record record)
 {
     ticker = (string)record.GetValue("ticker");
     // Convert price double from byte[].
     byte[] priceBytes = (byte[])record.GetValue("price");
     price = BitConverter.ToDouble(priceBytes, 0);
 }
        protected internal override void ParseResult(Connection conn)
        {
            // Read header.
            conn.ReadFully(dataBuffer, MSG_TOTAL_HEADER_SIZE);

            int resultCode = dataBuffer[13];

            if (resultCode == 0)
            {
                int generation = ByteUtil.BytesToInt(dataBuffer, 14);
                int expiration = ByteUtil.BytesToInt(dataBuffer, 18);
                record = new Record(null, generation, expiration);
            }
            else
            {
                if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    record = null;
                }
                else
                {
                    throw new AerospikeException(resultCode);
                }
            }
            EmptySocket(conn);
        }
            public void OnRecord(Key key, Record record)
            {
                parent.recordCount++;

                if ((parent.recordCount % 10000) == 0)
                {
                    parent.console.Info("Records " + parent.recordCount);
                }
            }
 public void OnSuccess(Key k, Record record)
 {
     parent.OnReadSuccess();
 }
        protected internal override void ParseResult()
        {
            int resultCode = dataBuffer[5];

            if (resultCode == 0)
            {
                int generation = ByteUtil.BytesToInt(dataBuffer, 6);
                int expiration = ByteUtil.BytesToInt(dataBuffer, 10);

                record = new Record(null, generation, expiration);
            }
            else
            {
                if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    record = null;
                }
                else
                {
                    throw new AerospikeException(resultCode);
                }
            }
        }