internal override void Visit(UploadVersionRequest req) { VersionList versionList = req.RemoteVerList as VersionList; if (versionList == null) { if (!this.dict.TryGetValue(req.RecordKey, out versionList)) { throw new TransactionException("The specified record does not exist."); } } if (versionList.TryAdd(req.VersionEntry, out VersionEntry remoteEntry)) { req.RemoteVerEntry = remoteEntry; req.Result = true; req.Finished = true; return; } else { // The same version key has been added before or by a concurrent tx. // The new version cannot be inserted. req.RemoteVerEntry = req.VersionEntry; req.Result = false; req.Finished = true; } }
internal override void Visit(DeleteVersionRequest req) { VersionList versionList = req.RemoteVerList as VersionList; // Only get the version list location when version list is null if (versionList == null) { if (!this.dict.TryGetValue(req.RecordKey, out versionList)) { req.Result = true; req.Finished = true; return; } } versionList.TryRemove(req.SenderId, req.VersionKey); req.Result = true; req.Finished = true; }
internal override void Visit(InitiGetVersionListRequest req) { if (!this.dict.TryGetValue(req.RecordKey, out VersionList versionList)) { VersionList newVersionList = new VersionList(); if (this.dict.TryAdd(req.RecordKey, newVersionList)) { // The version list is newly created by this tx. // No meaningful versions exist, except for the artificial entry as a tail pointer. req.RemoteVerList = newVersionList; req.Result = true; req.Finished = true; return; } } else { req.RemoteVerList = null; req.Result = false; req.Finished = true; } }