protected internal override void ParseRow(Key key)
 {
     if (resultCode == 0)
     {
         BatchRead record = records[batchIndex];
         record.record = ParseRecord();
     }
 }
        protected internal override void ParseRow(Key key)
        {
            BatchRead record = records[batchIndex];

            if (Util.ByteArrayEquals(key.digest, record.key.digest))
            {
                if (resultCode == 0)
                {
                    record.record = ParseRecord();
                }
            }
            else
            {
                throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + batchIndex);
            }
        }
Example #3
0
        public void SetBatchRead(BatchPolicy policy, List <BatchRead> records, BatchNode batch)
        {
            // Estimate full row size
            int[]     offsets    = batch.offsets;
            int       max        = batch.offsetsSize;
            ushort    fieldCount = policy.sendSetName ? (ushort)2 : (ushort)1;
            BatchRead prev       = null;

            Begin();
            dataOffset += FIELD_HEADER_SIZE + 5;

            for (int i = 0; i < max; i++)
            {
                BatchRead record   = records[offsets[i]];
                Key       key      = record.key;
                string[]  binNames = record.binNames;

                dataOffset += key.digest.Length + 4;

                // Avoid relatively expensive full equality checks for performance reasons.
                // Use reference equality only in hope that common namespaces/bin names are set from
                // fixed variables.  It's fine if equality not determined correctly because it just
                // results in more space used. The batch will still be correct.
                if (prev != null && prev.key.ns == key.ns &&
                    (!policy.sendSetName || prev.key.setName == key.setName) &&
                    prev.binNames == binNames && prev.readAllBins == record.readAllBins)
                {
                    // Can set repeat previous namespace/bin names to save space.
                    dataOffset++;
                }
                else
                {
                    // Estimate full header, namespace and bin names.
                    dataOffset += ByteUtil.EstimateSizeUtf8(key.ns) + FIELD_HEADER_SIZE + 6;

                    if (policy.sendSetName)
                    {
                        dataOffset += ByteUtil.EstimateSizeUtf8(key.setName) + FIELD_HEADER_SIZE;
                    }

                    if (binNames != null)
                    {
                        foreach (string binName in binNames)
                        {
                            EstimateOperationSize(binName);
                        }
                    }
                    prev = record;
                }
            }
            SizeBuffer();

            int readAttr = Command.INFO1_READ;

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

            WriteHeader(policy, readAttr | Command.INFO1_BATCH, 0, 1, 0);
            int fieldSizeOffset = dataOffset;

            WriteFieldHeader(0, policy.sendSetName ? FieldType.BATCH_INDEX_WITH_SET : FieldType.BATCH_INDEX);             // Need to update size at end

            ByteUtil.IntToBytes((uint)max, dataBuffer, dataOffset);
            dataOffset += 4;
            dataBuffer[dataOffset++] = (policy.allowInline) ? (byte)1 : (byte)0;
            prev = null;

            for (int i = 0; i < max; i++)
            {
                int index = offsets[i];
                ByteUtil.IntToBytes((uint)index, dataBuffer, dataOffset);
                dataOffset += 4;

                BatchRead record   = records[index];
                Key       key      = record.key;
                string[]  binNames = record.binNames;
                byte[]    digest   = key.digest;
                Array.Copy(digest, 0, dataBuffer, dataOffset, digest.Length);
                dataOffset += digest.Length;

                // Avoid relatively expensive full equality checks for performance reasons.
                // Use reference equality only in hope that common namespaces/bin names are set from
                // fixed variables.  It's fine if equality not determined correctly because it just
                // results in more space used. The batch will still be correct.
                if (prev != null && prev.key.ns == key.ns &&
                    (!policy.sendSetName || prev.key.setName == key.setName) &&
                    prev.binNames == binNames && prev.readAllBins == record.readAllBins)
                {
                    // Can set repeat previous namespace/bin names to save space.
                    dataBuffer[dataOffset++] = 1;                     // repeat
                }
                else
                {
                    // Write full header, namespace and bin names.
                    dataBuffer[dataOffset++] = 0;                     // do not repeat

                    if (binNames != null && binNames.Length != 0)
                    {
                        dataBuffer[dataOffset++] = (byte)readAttr;
                        dataOffset += ByteUtil.ShortToBytes(fieldCount, dataBuffer, dataOffset);
                        dataOffset += ByteUtil.ShortToBytes((ushort)binNames.Length, dataBuffer, dataOffset);
                        WriteField(key.ns, FieldType.NAMESPACE);

                        if (policy.sendSetName)
                        {
                            WriteField(key.setName, FieldType.TABLE);
                        }

                        foreach (string binName in binNames)
                        {
                            WriteOperation(binName, Operation.Type.READ);
                        }
                    }
                    else
                    {
                        dataBuffer[dataOffset++] = (byte)(readAttr | (record.readAllBins ? Command.INFO1_GET_ALL : Command.INFO1_NOBINDATA));
                        dataOffset += ByteUtil.ShortToBytes(fieldCount, dataBuffer, dataOffset);
                        dataOffset += ByteUtil.ShortToBytes(0, dataBuffer, dataOffset);
                        WriteField(key.ns, FieldType.NAMESPACE);

                        if (policy.sendSetName)
                        {
                            WriteField(key.setName, FieldType.TABLE);
                        }
                    }
                    prev = record;
                }
            }

            // Write real field size.
            ByteUtil.IntToBytes((uint)(dataOffset - MSG_TOTAL_HEADER_SIZE - 4), dataBuffer, fieldSizeOffset);
            End();
        }