/* * Handle write request from client */ public ImmutableVectorClock OnWriteRequest(WriteArguments arguments) { ImmutableVectorClock timestampToBroadcast; valueTimestamps.TryGetValue(arguments.PartitionId, out MutableVectorClock timestamp); // Wait for unreceived updates lock (timestamp) { while (VectorClock.HappensBefore(timestamp, arguments.Timestamp)) { Monitor.Wait(timestamp); } } emitedWritesTimestamps.TryGetValue( arguments.PartitionId, out MutableVectorClock emitedWriteTimestamp); // Prepare to emit one write lock (emitedWriteTimestamp) { emitedWriteTimestamp.Increment(serverConfig.ServerId); timestampToBroadcast = emitedWriteTimestamp.ToImmutable(); } // This waits for deliver and executes write ReliableBroadcastLayer.Instance.BroadcastWrite( arguments.PartitionId, arguments.ObjectId, arguments.ObjectValue, timestampToBroadcast); return(timestampToBroadcast); }
public int Write(String FileFullName, long Offset, int Count, Byte[] Buffer) { if (_ProtocolV3 == null) { throw new NFSConnectionException("NFS Client not connected!"); } if (_MountProtocolV3 == null) { throw new NFSMountConnectionException("NFS Device not connected!"); } int rCount = 0; if (_CurrentItem != FileFullName) { NFSAttributes Attributes = GetItemAttributes(FileFullName); _CurrentItemHandleObject = new NFSHandle(Attributes.Handle, V3.RPC.NFSv3Protocol.NFS_V3); _CurrentItem = FileFullName; } if (Count < Buffer.Length) { Array.Resize <byte>(ref Buffer, Count); } WriteArguments dpArgWrite = new WriteArguments(); dpArgWrite.File = _CurrentItemHandleObject; dpArgWrite.Offset = Offset; dpArgWrite.Count = Count; dpArgWrite.Data = Buffer; ResultObject <WriteAccessOK, WriteAccessFAIL> pAttrStat = _ProtocolV3.NFSPROC3_WRITE(dpArgWrite); if (pAttrStat != null) { if (pAttrStat.Status != NFSStats.NFS_OK) { ExceptionHelpers.ThrowException(pAttrStat.Status); } rCount = pAttrStat.OK.Count; } else { throw new NFSGeneralException("NFSPROC3_WRITE: failure"); } return(rCount); }
public void Write(WriteArguments arguments) { // Allow only one read at a time lock (writeLock) { // Get partition replicas urls partitionsDB.TryGetPartition(arguments.PartitionId, out ImmutableHashSet <string> partitionIds); List <string> otherReplicasIds = partitionIds.Where(id => id != config.ServerId).ToList(); if (otherReplicasIds.Count > 0) { // Lock object in all replicas Task[] tasks = otherReplicasIds.Select( id => FailureDetectionLayer.Instance.Lock( id, arguments.PartitionId, arguments.ObjectId)) .ToArray(); Task.WaitAll(tasks); } store.Lock( arguments.PartitionId, arguments.ObjectId); if (otherReplicasIds.Count > 0) { // Write object in all replicas Task[] tasks = otherReplicasIds.Select( id => FailureDetectionLayer.Instance.Write( id, arguments.PartitionId, arguments.ObjectId, arguments.ObjectValue)) .ToArray(); Task.WaitAll(tasks); } // Write value store.AddOrUpdate( arguments.PartitionId, arguments.ObjectId, arguments.ObjectValue); } }
public PipelineData Process(PipelineData Input) { RoutedPipelineStreamOptions Options = (RoutedPipelineStreamOptions)(Input.Options); Stream BaseStream = (Stream)Input.PrimaryData; switch (Options.Method) { case RoutedPipelineStreamMethod.READ: { ReadArguments readArguments = (ReadArguments)Input.SecondaryData; readArguments.Result = BaseStream.Read(readArguments.Buffer, readArguments.Offset, readArguments.Count); } break; case RoutedPipelineStreamMethod.SEEK: { SeekArguments seekArguments = (SeekArguments)Input.SecondaryData; seekArguments.Result = BaseStream.Seek(seekArguments.Offset, seekArguments.Origin); } break; case RoutedPipelineStreamMethod.SETLENGTH: BaseStream.SetLength((long)Input.SecondaryData); break; case RoutedPipelineStreamMethod.WRITE: { WriteArguments writeArguments = (WriteArguments)Input.SecondaryData; BaseStream.Write(writeArguments.Buffer, writeArguments.Offset, writeArguments.Count); } break; case RoutedPipelineStreamMethod.FLUSH: { BaseStream.Flush(); } break; default: Trace.WriteLine("Unknown stream operation"); break; } return(Input); }