Пример #1
0
 // wait for whatever we wait on
 /// <summary>Transmit the current buffer to bookkeeper.</summary>
 /// <remarks>
 /// Transmit the current buffer to bookkeeper.
 /// Synchronised at the FSEditLog level. #write() and #setReadyToFlush()
 /// are never called at the same time.
 /// </remarks>
 /// <exception cref="System.IO.IOException"/>
 private void Transmit()
 {
     if (!transmitResult.CompareAndSet(BKException.Code.Ok, BKException.Code.Ok))
     {
         throw new IOException("Trying to write to an errored stream;" + " Error code : ("
                               + transmitResult.Get() + ") " + BKException.GetMessage(transmitResult.Get()));
     }
     if (bufCurrent.GetLength() > 0)
     {
         byte[] entry = Arrays.CopyOf(bufCurrent.GetData(), bufCurrent.GetLength());
         lh.AsyncAddEntry(entry, this, null);
         bufCurrent.Reset();
         outstandingRequests.IncrementAndGet();
     }
 }
Пример #2
0
 /// <exception cref="System.IO.IOException"/>
 protected internal override void FlushAndSync(bool durable)
 {
     System.Diagnostics.Debug.Assert((syncLatch != null));
     try
     {
         syncLatch.Await();
     }
     catch (Exception ie)
     {
         throw new IOException("Interrupted waiting on latch", ie);
     }
     if (transmitResult.Get() != BKException.Code.Ok)
     {
         throw new IOException("Failed to write to bookkeeper; Error is (" + transmitResult
                               .Get() + ") " + BKException.GetMessage(transmitResult.Get()));
     }
     syncLatch = null;
 }
Пример #3
0
 public virtual void AddComplete(int rc, LedgerHandle handle, long entryId, object
                                 ctx)
 {
     lock (this)
     {
         outstandingRequests.DecrementAndGet();
         if (!transmitResult.CompareAndSet(BKException.Code.Ok, rc))
         {
             Log.Warn("Tried to set transmit result to (" + rc + ") \"" + BKException.GetMessage
                          (rc) + "\"" + " but is already (" + transmitResult.Get() + ") \"" + BKException.
                      GetMessage(transmitResult.Get()) + "\"");
         }
         CountDownLatch l = syncLatch;
         if (l != null)
         {
             l.CountDown();
         }
     }
 }