Beispiel #1
0
        public void WriteCreateOrUpdateCommand(byte[] prefix, ByteBuffer key, ByteBuffer value, out uint valueFileId, out uint valueOfs, out int valueSize)
        {
            var command = KVCommandType.CreateOrUpdate;

            if (_compression.ShouldTryToCompressKey(prefix.Length + key.Length))
            {
                if (prefix.Length != 0)
                {
                    var fullkey = new byte[prefix.Length + key.Length];
                    Array.Copy(prefix, 0, fullkey, 0, prefix.Length);
                    Array.Copy(key.Buffer, key.Offset, fullkey, prefix.Length, key.Length);
                    prefix = BitArrayManipulation.EmptyByteArray;
                    key    = ByteBuffer.NewAsync(fullkey);
                }
                if (_compression.CompressKey(ref key))
                {
                    command |= KVCommandType.FirstParamCompressed;
                }
            }
            valueSize = value.Length;
            if (_compression.CompressValue(ref value))
            {
                command  |= KVCommandType.SecondParamCompressed;
                valueSize = -value.Length;
            }
            if (_writerWithTransactionLog.GetCurrentPosition() + prefix.Length + key.Length + 16 > MaxTrLogFileSize)
            {
                WriteStartOfNewTransactionLogFile();
            }
            _writerWithTransactionLog.WriteUInt8((byte)command);
            _writerWithTransactionLog.WriteVInt32(prefix.Length + key.Length);
            _writerWithTransactionLog.WriteVInt32(value.Length);
            _writerWithTransactionLog.WriteBlock(prefix);
            _writerWithTransactionLog.WriteBlock(key);
            if (valueSize != 0)
            {
                if (valueSize > 0 && valueSize < MaxValueSizeInlineInMemory)
                {
                    StoreValueInlineInMemory(value, out valueOfs, out valueSize);
                    valueFileId = 0;
                }
                else
                {
                    valueFileId = _fileIdWithTransactionLog;
                    valueOfs    = (uint)_writerWithTransactionLog.GetCurrentPosition();
                }
                _writerWithTransactionLog.WriteBlock(value);
            }
            else
            {
                valueFileId = 0;
                valueOfs    = 0;
            }
        }
Beispiel #2
0
 internal void WriteHeader(AbstractBufferedWriter writer)
 {
     FileCollectionWithFileInfos.WriteHeader(writer, _guid);
     writer.WriteUInt8((byte)KVFileType.TransactionLog);
     writer.WriteVInt64(_generation);
     writer.WriteVInt32((int)_previousFileId);
 }
Beispiel #3
0
 public void SetKeyPrefix(byte[] prefix, int prefixOfs, int prefixLen)
 {
     lock (_log)
     {
         _log.WriteUInt8((byte)KVReplayOperation.SetKeyPrefix);
         _log.WriteVUInt32(TrIndex);
         _log.WriteVInt32(prefixLen);
         _log.WriteVInt32(prefixOfs);
         _log.WriteBlock(prefix, prefixOfs, prefixLen);
         _log.FlushBuffer();
     }
     _tr.SetKeyPrefix(prefix, prefixOfs, prefixLen);
 }