public async Task Write(GStoreObjectIdentifier gStoreObjectIdentifier, string newValue) { try { if (!connectionManager.IsMasterForPartition(gStoreObjectIdentifier.PartitionId)) { throw new Exception("Not master"); } // Acquire lock on local object ReaderWriterLockEnhancedSlim objectLock = GetObjectLock(gStoreObjectIdentifier); int lockId = objectLock.EnterWriteLock(); // Send lock requests to all remote objects IDictionary <string, int> replicaLocks = await LockController.ExecuteAsync(connectionManager, gStoreObjectIdentifier); // Once lock confirmations arrive, write to local object and unlock it GStoreObject gStoreObject = AddOrUpdate(gStoreObjectIdentifier, newValue); objectLock.ExitWriteLock(lockId); // Send write requests to all remote objects await WriteReplicaController.ExecuteAsync(connectionManager, gStoreObject, replicaLocks); } catch (Exception e) { Console.WriteLine(e); } }
public void Write(GStoreObjectIdentifier gStoreObjectIdentifier, string newValue) { // Acquire lock on local object ReaderWriterLockSlim objectLock = GetObjectLock(gStoreObjectIdentifier); objectLock.EnterWriteLock(); try { int version = GetAndIncrementObjectVersionNumber(gStoreObjectIdentifier); AddOrUpdateObjectVersionServerWriter(gStoreObjectIdentifier, connectionManager.SelfServerId); GStoreObject gStoreObject = AddOrUpdate(gStoreObjectIdentifier, newValue); _ = WriteReplicaController.ExecuteAsync(connectionManager, gStoreObject, version); } catch (Exception e) { Console.WriteLine(e); } finally { objectLock.ExitWriteLock(); } }