Ejemplo n.º 1
0
 internal void WriteHeader(AbstractBufferedWriter writer)
 {
     FileCollectionWithFileInfos.WriteHeader(writer, _guid);
     writer.WriteUInt8((byte)KVFileType.ModernKeyIndex);
     writer.WriteVInt64(_generation);
     writer.WriteVUInt32(_trLogFileId);
     writer.WriteVUInt32(_trLogOffset);
     writer.WriteVUInt64((ulong)_keyValueCount);
     writer.WriteVUInt64(_commitUlong);
     writer.WriteUInt8((byte)_compressionType);
 }
Ejemplo n.º 2
0
 public bool Open(IPositionLessStream positionLessStream, bool dispose)
 {
     lock (_log)
     {
         _log.WriteUInt8((byte)KVReplayOperation.Open);
         ulong size = positionLessStream.GetSize();
         _log.WriteVUInt64(size);
         ulong pos = 0;
         var   buf = new byte[4096];
         while (pos < size)
         {
             var read = positionLessStream.Read(buf, 0, buf.Length, pos);
             // Next 2 conditions should not happen or file is mutated when it should not
             if (read == 0)
             {
                 break;
             }
             if ((ulong)read > size - pos)
             {
                 read = (int)(size - pos);
             }
             _log.WriteBlock(buf, 0, read);
             pos += (ulong)read;
         }
         while (pos < size)
         {
             _log.WriteUInt8(0);
             pos++;
         }
         _log.FlushBuffer();
     }
     return(_db.Open(positionLessStream, dispose));
 }
Ejemplo n.º 3
0
 internal void WriteHeader(AbstractBufferedWriter writer)
 {
     writer.WriteByteArrayRaw(DiskChunkCache.MagicStartOfFile);
     writer.WriteUInt8((byte)DiskChunkFileType.HashIndex);
     writer.WriteVInt64(_generation);
     writer.WriteVUInt32((uint)KeySize);
     writer.WriteVUInt64((ulong)KeyValueCount);
 }
Ejemplo n.º 4
0
        internal void WriteHeader(AbstractBufferedWriter writer)
        {
            FileCollectionWithFileInfos.WriteHeader(writer, _guid);
            writer.WriteUInt8((byte)KVFileType.ModernKeyIndexWithUlongs);
            writer.WriteVInt64(_generation);
            writer.WriteVUInt32(_trLogFileId);
            writer.WriteVUInt32(_trLogOffset);
            writer.WriteVUInt64((ulong)_keyValueCount);
            writer.WriteVUInt64(_commitUlong);
            writer.WriteUInt8((byte)_compressionType);
            var ulongCount = (uint)(_ulongs?.Length ?? 0);

            writer.WriteVUInt32(ulongCount);
            if (ulongCount > 0)
            {
                for (var i = 0; i < ulongCount; i++)
                {
                    writer.WriteVUInt64(_ulongs ![i]);
Ejemplo n.º 5
0
        // ReSharper disable UnusedMember.Global
        public static void SaverImpl <T>(AbstractBufferedWriter writer, IList <T> ilist) where T : class
        // ReSharper restore UnusedMember.Global
        {
            if (ilist == null)
            {
                writer.WriteVUInt32(0);
                return;
            }
            var oids = ((ListOfDBObject <T>)ilist).Oids;

            writer.WriteVUInt32((uint)oids.Count);
            foreach (var oid in oids)
            {
                writer.WriteVUInt64(oid);
            }
        }
Ejemplo n.º 6
0
 public void Persist(AbstractBufferedWriter writer, Action <AbstractBufferedWriter, ITypeDescriptor> nestedDescriptorPersistor)
 {
     writer.WriteString(_name);
     writer.WriteVUInt32((_signed ? 1u : 0) + (_flags ? 2u : 0) + 4u * (uint)_pairs.Count);
     foreach (var pair in _pairs)
     {
         writer.WriteString(pair.Key);
         if (_signed)
         {
             writer.WriteVInt64((long)pair.Value);
         }
         else
         {
             writer.WriteVUInt64(pair.Value);
         }
     }
 }
Ejemplo n.º 7
0
        internal void CommitWrittingTransaction(IBTreeRootNode btreeRoot, bool temporaryCloseTransactionLog)
        {
            var deltaUlong = unchecked (btreeRoot.CommitUlong - _lastCommited.CommitUlong);

            if (deltaUlong != 0)
            {
                _writerWithTransactionLog.WriteUInt8((byte)KVCommandType.CommitWithDeltaUlong);
                _writerWithTransactionLog.WriteVUInt64(deltaUlong);
            }
            else
            {
                _writerWithTransactionLog.WriteUInt8((byte)KVCommandType.Commit);
            }
            if (DurableTransactions || !temporaryCloseTransactionLog)
            {
                _writerWithTransactionLog.FlushBuffer();
            }
            UpdateTransactionLogInBTreeRoot(btreeRoot);
            if (DurableTransactions)
            {
                _fileWithTransactionLog.HardFlush();
            }
            if (temporaryCloseTransactionLog)
            {
                _writerWithTransactionLog.WriteUInt8((byte)KVCommandType.TemporaryEndOfFile);
                _writerWithTransactionLog.FlushBuffer();
                if (DurableTransactions)
                {
                    _fileWithTransactionLog.HardFlush();
                }
                _fileWithTransactionLog.Truncate();
            }
            lock (_writeLock)
            {
                _writingTransaction = null;
                _lastCommited       = btreeRoot;
                TryDequeWaiterForWrittingTransaction();
            }
        }