private OperationType ParseType(RecordIndexEntry index) { switch (index.ActiveFileId) { case InsertedButNotCommitted: return(OperationType.Insert); case DeletededButNotCommitted: return(OperationType.Detete); default: return(OperationType.Update); } }
public void MarkIndexDeleted(RecordIndexEntry index, Guid transactionId) { lock (this.RecordIndices) { foreach (var item in RecordIndices) { if (item.Key == index.Key) { item.ShadowFileId = item.ActiveFileId; item.ActiveFileId = SimpleDatabase.DeletededButNotCommitted; item.IsDirty = 1; item.TransactionId = transactionId; } } } }
public void IndexTest() { var target = new SimpleDatabase_Accessor("RRR", false, true); target.CreateTable("Car", 96, 36); PageTable pt = target.DiskReadPageTable("Car"); pt.InsertIndex("aa", 1, 1, 1, Guid.Empty); pt.InsertIndex("bb", 1, 1, 1, Guid.Empty); var r = new RecordIndexEntry { Key = "aa" }; pt.WipeoutIndex(r, Guid.Empty); Assert.IsFalse((from i in pt.RecordIndices where i.Key == "aa" select i).Any()); pt.InsertIndex("aa", 1, 1, 1, Guid.Empty); Assert.IsTrue(pt.RecordIndices[0].Key == "aa"); }
public void WipeoutIndex(RecordIndexEntry index, Guid transactionId) { lock (this.RecordIndices) { foreach (var item in RecordIndices) { if (item.Key == index.Key) { item.Key = new string('\0', _keySize); item.PageIndex = 0; item.RowIndex = 0; item.ActiveFileId = 0; item.ShadowFileId = 0; item.IsDirty = 0; item.TransactionId = Guid.Empty; } } } }
public PageTable(byte[] data, int pageTableSize = SimpleDatabase.DefaultPageSize, int keySize = 36) { if (pageTableSize != data.Length) { throw new ArgumentException("invalid PageTable data", "data"); } PageTableSize = pageTableSize; this._keySize = keySize; this.RecordIndexEntrySizeInBytes = keySize + 5 * 4 + 32; //PageIndex, RowIndex, ActiveFileId, ShadowFileId, IsDirty, TransactionKey var encoder = new UTF8Encoding(); RecordIndices = new RecordIndexEntry[PageTableSize / RecordIndexEntrySizeInBytes]; for (var i = 0; i < PageTableSize / RecordIndexEntrySizeInBytes; i++) { var p = i * RecordIndexEntrySizeInBytes; var keyBuffer = new byte[keySize]; Array.Copy(data, p, keyBuffer, 0, keySize); var pi = new RecordIndexEntry { Key = encoder.GetString(keyBuffer), PageIndex = BitConverter.ToInt32(data, p + keySize), RowIndex = BitConverter.ToInt32(data, p + keySize + 4), ActiveFileId = BitConverter.ToInt32(data, p + keySize + 4 + 4), ShadowFileId = BitConverter.ToInt32(data, p + keySize + 4 + 4 + 4), IsDirty = BitConverter.ToInt32(data, p + keySize + 4 + 4 + 4 + 4), }; Guid tempTid; if (Guid.TryParse(encoder.GetString(data, p + keySize + 4 + 4 + 4 + 4 + 4, 32), out tempTid) && tempTid != Guid.Empty) { pi.TransactionId = tempTid; } RecordIndices[i] = pi; } }
public PageTable(byte[] data, int pageTableSize = SimpleDatabase.DefaultPageSize, int keySize = 36) { if (pageTableSize != data.Length) { throw new ArgumentException("invalid PageTable data", "data"); } PageTableSize = pageTableSize; this._keySize = keySize; this.RecordIndexEntrySizeInBytes = keySize + 5 * 4 + 32; //PageIndex, RowIndex, ActiveFileId, ShadowFileId, IsDirty, TransactionKey var encoder = new UTF8Encoding(); RecordIndices = new RecordIndexEntry[PageTableSize/RecordIndexEntrySizeInBytes]; for (var i = 0; i < PageTableSize / RecordIndexEntrySizeInBytes; i++) { var p = i * RecordIndexEntrySizeInBytes; var keyBuffer = new byte[keySize]; Array.Copy(data, p, keyBuffer, 0, keySize); var pi = new RecordIndexEntry { Key = encoder.GetString(keyBuffer), PageIndex = BitConverter.ToInt32(data, p + keySize), RowIndex = BitConverter.ToInt32(data, p + keySize + 4), ActiveFileId = BitConverter.ToInt32(data, p + keySize + 4 + 4), ShadowFileId = BitConverter.ToInt32(data, p + keySize + 4 + 4 + 4), IsDirty = BitConverter.ToInt32(data, p + keySize + 4 + 4 + 4 + 4), }; Guid tempTid; if (Guid.TryParse(encoder.GetString(data, p + keySize + 4 + 4 + 4 + 4 + 4, 32), out tempTid) && tempTid != Guid.Empty) { pi.TransactionId = tempTid; } RecordIndices[i] = pi; } }
private OperationType ParseType(RecordIndexEntry index) { switch (index.ActiveFileId) { case InsertedButNotCommitted: return OperationType.Insert; case DeletededButNotCommitted: return OperationType.Detete; default: return OperationType.Update; } }