internal void Add(ValueVersion <T> v) { this.rwl.EnterWriteLock(); try { this.values.Add(v); var count = this.values.Count; if (count > 1) { var lastVersion = this.values[count - 2].version; if (lastVersion >= v.version) { Environment.FailFast(string.Format("Received lower version value {1} after adding higher version {0}. Value: {2], List: {3]", lastVersion, v.version, v, this.values)); } } } finally { this.rwl.ExitWriteLock(); } }
static public SyncVersionList <T> Create(ValueVersion <T> value) { var ret = new SyncVersionList <T>(); ret.Initliaze(value); return(ret); }
public void Can_remove_item_from_table_when_there_is_more_than_single_item() { using (var table = new PersistentHashTable(testDatabase)) { table.Initialize(); ValueVersion versionOfA = null, versionOfC = null; table.Batch(actions => { versionOfA = actions.Put( new PutRequest { Key = "a", ParentVersions = new ValueVersion[0], Bytes = new byte[] { 1 } } ).Version; actions.Put(new PutRequest { Key = "b", ParentVersions = new ValueVersion[0], Bytes = new byte[] { 1 } }); versionOfC = actions.Put( new PutRequest { Key = "c", ParentVersions = new ValueVersion[0], Bytes = new byte[] { 1 } }).Version; actions.Put( new PutRequest { Key = "d", ParentVersions = new ValueVersion[0], Bytes = new byte[] { 1 } }); actions.Commit(); }); table.Batch(actions => { bool removed = actions.Remove(new RemoveRequest { Key = "a", SpecificVersion = versionOfA }); Assert.True(removed); removed = actions.Remove(new RemoveRequest { Key = "c", SpecificVersion = versionOfC }); Assert.True(removed); actions.Commit(); }); } }
private static void RegisterRemovalForReplication(RemoveRequest request, PersistentHashTableActions actions, ValueVersion version) { foreach (var hash in actions.GetReplicationHashes(request.Key, version)) { actions.AddReplicationRemovalInfo( request.Key, version, hash ); } }
public RemovingValues() { node = MockRepository.GenerateStub <IDistributedHashTableNode>(); topologyVersion = 1; node.Stub(x => x.GetTopologyVersion()).Return(topologyVersion); distributedHashTableStorage = new DistributedHashTableStorage("test.esent", node); var results = distributedHashTableStorage.Put(topologyVersion, new ExtendedPutRequest { Key = "test", Bytes = new byte[] { 1, 2, 4 }, Segment = 0, }); version = results[0].Version; }
private static void RegisterRemovalForReplication(RemoveRequest request, PersistentHashTableActions actions, ValueVersion version) { foreach (var hash in actions.GetReplicationHashes(request.Key, version)) { actions.AddReplicationRemovalInfo( request.Key, version, hash ); } }
void Initliaze(ValueVersion <T> value) { this.rwl = new ReaderWriterLockSlim(); this.values = new List <ValueVersion <T> >(); this.values.Add(value); }
public RemovingValues() { node = MockRepository.GenerateStub<IDistributedHashTableNode>(); topologyVersion = 1; node.Stub(x => x.GetTopologyVersion()).Return(topologyVersion); distributedHashTableStorage = new DistributedHashTableStorage("test.esent", node); var results = distributedHashTableStorage.Put(topologyVersion, new ExtendedPutRequest { Key = "test", Bytes = new byte[] { 1, 2, 4 }, Segment = 0, }); version = results[0].Version; }
private Value ReadValueFromDataTable(ValueVersion version, string key) { var expiresAtBinary = Api.RetrieveColumnAsDouble(session, data, dataColumns["expiresAt"]); DateTime? expiresAt = null; if (expiresAtBinary.HasValue) { expiresAt = DateTime.FromOADate(expiresAtBinary.Value); if (DateTime.Now > expiresAt) return null; } return new Value { Version = version, Key = key, Timestamp = DateTime.FromOADate(Api.RetrieveColumnAsDouble(session,data,dataColumns["timestamp"]).Value), ParentVersions = GetParentVersions(), Data = Api.RetrieveColumn(session, data, dataColumns["data"]), Sha256Hash = Api.RetrieveColumn(session, data, dataColumns["sha256_hash"]), ReadOnly = Api.RetrieveColumnAsBoolean(session, data, dataColumns["readonly"]).Value, ExpiresAt = expiresAt }; }
private string GetKey(string key, ValueVersion version) { return GetKey(key) + "#" + version.InstanceId + "/" + version.Number; }
private bool DoesAllVersionsMatch(string key, ValueVersion[] parentVersions) { var activeVersions = GatherActiveVersions(key); if (activeVersions.Length != parentVersions.Length) return false; activeVersions = activeVersions .OrderBy(x => x) .ToArray(); parentVersions = parentVersions.OrderBy(x => x).ToArray(); for (int i = 0; i < activeVersions.Length; i++) { if (activeVersions[i].Number != parentVersions[i].Number || activeVersions[i].InstanceId != parentVersions[i].InstanceId) return false; } return true; }