public PartitionTxData ReadTxLogFromPartition(ReadContext readCache, TxRec txRec = null) { if (txRec == null) { return(ReadTxLogFromFile(readCache)); } return(ReadTxLogFromFileAndTxRec(readCache, txRec)); }
public PartitionTxData ReadTxLogFromPartition(ReadContext readCache, TxRec txRec = null) { if (!_isStorageInitialized) { InitializeStorage(); } return(_txSupport.ReadTxLogFromPartition(readCache, txRec)); }
public TT Read <TT>(long rowID, ReadContext readContext) { if (!_isStorageInitialized) { InitializeStorage(); } return((TT)_fieldSerializer.Read(rowID, readContext)); }
public PartitionTxData ReadTxLogFromFile(ReadContext readCache) { long nextRowID = -1L; string lastRowIDFilename = null; var pd = new PartitionTxData(_metadata.FileCount, _partitionID, _startDate, _endTime, readCache); for (int i = 0; i < _storage.OpenFileCount; i++) { var file = _storage.GetOpenedFileByID(i); if (file == null) { continue; } IColumnMetadata column; long fileAppendOffset; try { fileAppendOffset = file.GetAppendOffset(); pd.AppendOffset[file.FileID] = fileAppendOffset; if (file.DataType == EDataType.Symrk || file.DataType == EDataType.Datak) { var keyBlockOffset = file.ReadInt64(MetadataConstants.K_FILE_KEY_BLOCK_OFFSET); pd.SymbolData[file.FileID].KeyBlockOffset = keyBlockOffset; var keyBlockSize = file.ReadInt64(keyBlockOffset); pd.SymbolData[file.FileID].KeyBlockSize = (int)keyBlockSize; } column = _metadata.GetColumnByID(file.ColumnID); if (_metadata.TimestampColumnID == column.ColumnID) { var timestamp = file.ReadInt64(fileAppendOffset - TIMESTAMP_DATA_SIZE); pd.LastTimestamp = timestamp; } } catch (Exception ex) { if (ex is NFSdbPartitionException) { throw; } throw new NFSdbTransactionStateExcepton( string.Format("Error reading transaction state from file {0}", file.Filename), ex); } var size = StorageSizeUtils.GetRecordSize(column, file.DataType); if (size > 0) { long rowId = fileAppendOffset / size; if (nextRowID >= 0 && rowId != nextRowID) { throw new NFSdbTransactionStateExcepton( string.Format("File {0} has last rowID" + " different than file {1}. Journal is not consistent" + " or mutiple writes happened", file.Filename, lastRowIDFilename)); } nextRowID = rowId; lastRowIDFilename = file.Filename; } } pd.NextRowID = nextRowID; return(pd); }
private PartitionTxData ReadTxLogFromFileAndTxRec(ReadContext readCache, TxRec txRec) { int symrRead = 0; var pd = new PartitionTxData(_metadata.FileCount, _partitionID, _startDate, _endTime, readCache); long nextRowID = RowIDUtil.ToLocalRowID(txRec.JournalMaxRowID - 1) + 1; pd.NextRowID = nextRowID; for (int i = 0; i < _storage.OpenFileCount; i++) { var file = _storage.GetOpenedFileByID(i); if (file == null) { continue; } try { if (file.DataType == EDataType.Symrk && txRec.SymbolTableIndexPointers != null) { var blockOffset = txRec.SymbolTableIndexPointers[symrRead++]; pd.SymbolData[file.FileID].KeyBlockOffset = blockOffset; long keyBlockSize = file.ReadInt64(blockOffset + MetadataConstants.K_FILE_ROW_BLOCK_LEN_OFFSET); pd.SymbolData[file.FileID].KeyBlockSize = (int)keyBlockSize; pd.AppendOffset[file.FileID] = blockOffset + keyBlockSize; } else if (file.DataType == EDataType.Datak && txRec.IndexPointers != null) { var blockOffset = txRec.IndexPointers[file.ColumnID]; pd.SymbolData[file.FileID].KeyBlockOffset = blockOffset; long keyBlockSize = file.ReadInt64(blockOffset + MetadataConstants.K_FILE_ROW_BLOCK_LEN_OFFSET); pd.SymbolData[file.FileID].KeyBlockSize = (int)keyBlockSize; pd.AppendOffset[file.FileID] = blockOffset + keyBlockSize; } else { var column = _metadata.GetColumnByID(file.ColumnID); var size = StorageSizeUtils.GetRecordSize(column, file.DataType); if (size > 0) { // Fixed column. pd.AppendOffset[file.FileID] = nextRowID * size; } else { // Variable column. pd.AppendOffset[file.FileID] = file.GetAppendOffset(); } if (_metadata.TimestampColumnID == column.ColumnID) { var timestamp = file.ReadInt64(pd.AppendOffset[file.FileID] - TIMESTAMP_DATA_SIZE); pd.LastTimestamp = timestamp; } } } catch (Exception ex) { if (ex is NFSdbPartitionException) { throw; } throw new NFSdbTransactionStateExcepton( string.Format("Error reading transaction state from file {0}", file.Filename), ex); } } pd.NextRowID = nextRowID; return(pd); }