public IndexAddressColumn(IRawFile kData, int capacity, long recordCountHint) { _fileID = kData.FileID; _partitionID = kData.PartitionID; int keycountHint = Math.Max(capacity, 1); // Nuber of records per keyblock // is a half of statistically expected // but minimum size is 10 _rowBlockLenBitHint = (int)Math.Floor(Math.Log(Math.Max(recordCountHint / keycountHint / 2, 16), 2.0)) - 1; _rowBlockLenBitHint = Math.Max(_rowBlockLenBitHint, 4); int rowBlockLen = 1 << _rowBlockLenBitHint; _kData = kData; if (kData.GetAppendOffset() > 0) { rowBlockLen = _kData.ReadInt32(ROW_BLOK_LEN_ADDRESS_OFFSET); _rowBlockLenBitHint = (int)Math.Log(rowBlockLen, 2); if (1 << _rowBlockLenBitHint != rowBlockLen) { throw new NFSdbInvalidStateException("Row block length specified in file '{0}' equals " + "{1}. Only power of 2 values are supported.", _kData.Filename, rowBlockLen); } } else if (kData.Access == EFileAccess.ReadWrite) { kData.WriteInt64(0, rowBlockLen); // 8 kData.WriteInt64(KEY_BLOCK_ADDRESS_OFFSET, INITIAL_KEYBLOCK_OFFSET); // 8 const int defaultKeyBlockSize = 0; kData.WriteInt64(INITIAL_KEYBLOCK_OFFSET, defaultKeyBlockSize); // 8 kData.WriteInt64(INITIAL_KEYBLOCK_OFFSET + 8, 0); // 8 kData.SetAppendOffset(INITIAL_APPEND_OFFSET); } _rowBlockSize = rowBlockLen * 8 + 8; }
public void Add(int key, long value, PartitionTxData tx) { var keyRecOffset = _indexAddress.ReadKeyRecordOffset(key, tx); var blockOffset = _kData.ReadInt64(keyRecOffset); long offset = keyRecOffset + 8; var rowCount = _kData.ReadInt64(offset); var cellIndex = (int)(rowCount & (_rowBlockLen - 1)); if (blockOffset == 0 || cellIndex == 0) { var prevRowBlockOffset = blockOffset; blockOffset = tx.AppendOffset[_rFileID] + _rowBlockSize; tx.AppendOffset[_rFileID] = blockOffset; _rData.WriteInt64(blockOffset - 8, prevRowBlockOffset); // Save block offset in k file _kData.WriteInt64(keyRecOffset, blockOffset); } // Save value in index _rData.WriteInt64(blockOffset - _rowBlockSize + 8 * cellIndex, value); // Save row count in k file _kData.WriteInt64(offset, rowCount + 1); }
public void SetBytes(long rowID, byte[] value, PartitionTxData tx) { var offset = rowID * MetadataConstants.STRING_INDEX_FILE_RECORD_SIZE; if (value != null) { var writeOffset = tx.AppendOffset[_data.FileID]; _index.WriteInt64(offset, writeOffset); var size = value.Length; WriteLength(writeOffset, size); _data.WriteBytes(writeOffset + HEADER_SIZE, value, 0, size); tx.AppendOffset[_data.FileID] = writeOffset + HEADER_SIZE + size; } else { _index.WriteInt64(offset, MetadataConstants.INDEX_NULL_DATA_VALUE); } }
public void SetInt64(long rowID, long value) { var offset = rowID * _sizeBytes; _storage.WriteInt64(offset, value); }
public void SaveKeyRecord(KeyRecord rowBlockDet, ITransactionContext tx) { _kData.WriteInt64(rowBlockDet.KeyOffset, rowBlockDet.BlockOffset); _kData.WriteInt64(rowBlockDet.KeyOffset + 8, rowBlockDet.RowCount); }