mirror of
https://github.com/ZoneTree/ZoneTree.git
synced 2026-10-28 12:47:01 +08:00
Non-transactional upsert method cannot return upsert status.
This commit is contained in:
@@ -182,7 +182,8 @@ public sealed class ZoneTree<TKey, TValue> : IZoneTree<TKey, TValue>, IZoneTreeM
|
||||
{
|
||||
if (ContainsKey(key))
|
||||
return false;
|
||||
return Upsert(key, value);
|
||||
Upsert(key, value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +195,8 @@ public sealed class ZoneTree<TKey, TValue> : IZoneTree<TKey, TValue>, IZoneTreeM
|
||||
{
|
||||
if (!ContainsKey(key))
|
||||
return false;
|
||||
return Upsert(key, value);
|
||||
Upsert(key, value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,15 +243,15 @@ public sealed class ZoneTree<TKey, TValue> : IZoneTree<TKey, TValue>, IZoneTreeM
|
||||
}
|
||||
}
|
||||
|
||||
public bool AtomicUpsert(in TKey key, in TValue value)
|
||||
public void AtomicUpsert(in TKey key, in TValue value)
|
||||
{
|
||||
lock (AtomicUpdateLock)
|
||||
{
|
||||
return Upsert(in key, in value);
|
||||
Upsert(in key, in value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Upsert(in TKey key, in TValue value)
|
||||
public void Upsert(in TKey key, in TValue value)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
@@ -265,7 +267,7 @@ public sealed class ZoneTree<TKey, TValue> : IZoneTree<TKey, TValue>, IZoneTreeM
|
||||
MoveSegmentZeroForward(segmentZero);
|
||||
continue;
|
||||
default:
|
||||
return status == AddOrUpdateResult.ADDED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,7 +353,6 @@ public sealed class ZoneTree<TKey, TValue> : IZoneTree<TKey, TValue>, IZoneTreeM
|
||||
DiskSegment.SegmentId,
|
||||
ReadOnlySegmentQueue.Select(x => x.SegmentId).Reverse().ToArray());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async ValueTask<MergeResult> StartMergeOperation()
|
||||
|
||||
@@ -29,7 +29,8 @@ public interface ITransactionalZoneTree<TKey, TValue> : IDisposable
|
||||
/// <param name="transactionId">Transaction Id</param>
|
||||
/// <param name="key">Key</param>
|
||||
/// <param name="value">Value</param>
|
||||
/// <returns></returns>
|
||||
/// /// <returns>true if the key/value pair was inserted;
|
||||
/// false if the key/value pair was updated.</returns>
|
||||
/// <exception cref="TransactionAbortedException"></exception>
|
||||
bool Upsert(long transactionId, in TKey key, in TValue value);
|
||||
|
||||
@@ -112,8 +113,7 @@ public interface ITransactionalZoneTree<TKey, TValue> : IDisposable
|
||||
/// </summary>
|
||||
/// <param name="key">Key</param>
|
||||
/// <param name="value">Value</param>
|
||||
/// <returns></returns>
|
||||
bool UpsertAutoCommit(in TKey key, in TValue value);
|
||||
void UpsertAutoCommit(in TKey key, in TValue value);
|
||||
|
||||
/// <summary>
|
||||
/// Starts a transaction,
|
||||
|
||||
@@ -55,10 +55,8 @@ public interface IZoneTree<TKey, TValue> : IDisposable
|
||||
/// </summary>
|
||||
/// <param name="key">The key of the element to upsert.</param>
|
||||
/// <param name="value">The value of the element to upsert. It can be null.</param>
|
||||
/// <returns>true if the key/value pair was inserted;
|
||||
/// false if the key/value pair was updated.</returns>
|
||||
/// <exception cref="ArgumentNullException">key is null.</exception>
|
||||
bool AtomicUpsert(in TKey key, in TValue value);
|
||||
void AtomicUpsert(in TKey key, in TValue value);
|
||||
|
||||
/// <summary>
|
||||
/// Adds or updates the specified key/value pair.
|
||||
@@ -89,10 +87,8 @@ public interface IZoneTree<TKey, TValue> : IDisposable
|
||||
/// </remarks>
|
||||
/// <param name="key">The key of the element to upsert.</param>
|
||||
/// <param name="value">The value of the element to upsert. It can be null.</param>
|
||||
/// <returns>true if the key/value pair was inserted;
|
||||
/// false if the key/value pair was updated.</returns>
|
||||
/// <exception cref="ArgumentNullException">key is null.</exception>
|
||||
bool Upsert(in TKey key, in TValue value);
|
||||
void Upsert(in TKey key, in TValue value);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to delete the specified key.
|
||||
|
||||
@@ -366,21 +366,18 @@ public sealed class OptimisticZoneTree<TKey, TValue> :
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpsertAutoCommit(in TKey key, in TValue value)
|
||||
public void UpsertAutoCommit(in TKey key, in TValue value)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
var transactionId = BeginTransaction();
|
||||
var transaction = GetOrCreateTransaction(transactionId);
|
||||
var readWriteStamp = new ReadWriteStamp
|
||||
{
|
||||
WriteStamp = transactionId
|
||||
};
|
||||
TransactionLog.TryGetReadWriteStamp(key, out var readWriteStamp);
|
||||
readWriteStamp.WriteStamp = transactionId;
|
||||
TransactionLog.AddOrUpdateReadWriteStamp(key, in readWriteStamp);
|
||||
var result = ZoneTree.Upsert(in key, in value);
|
||||
ZoneTree.Upsert(in key, in value);
|
||||
transaction.IsReadyToCommit = true;
|
||||
DoCommit(transaction);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,10 +387,8 @@ public sealed class OptimisticZoneTree<TKey, TValue> :
|
||||
{
|
||||
var transactionId = BeginTransaction();
|
||||
var transaction = GetOrCreateTransaction(transactionId);
|
||||
var readWriteStamp = new ReadWriteStamp
|
||||
{
|
||||
WriteStamp = transactionId
|
||||
};
|
||||
TransactionLog.TryGetReadWriteStamp(key, out var readWriteStamp);
|
||||
readWriteStamp.WriteStamp = transactionId;
|
||||
TransactionLog.AddOrUpdateReadWriteStamp(key, in readWriteStamp);
|
||||
ZoneTree.ForceDelete(in key);
|
||||
transaction.IsReadyToCommit = true;
|
||||
|
||||
Reference in New Issue
Block a user