@@ -931,14 +931,29 @@ public bool CommitStrongly(out long commitTail, out long actualCommitNum, bool s
931
931
public async ValueTask CommitAsync ( CancellationToken token = default )
932
932
{
933
933
token . ThrowIfCancellationRequested ( ) ;
934
+
935
+ // Take a lower-bound of the content of this commit in case our request is filtered but we need to wait
936
+ var tail = TailAddress ;
937
+ var lastCommit = commitNum ;
938
+
934
939
var task = CommitTask ;
935
- if ( ! CommitInternal ( out var tailAddress , out var actualCommitNum , true , null , - 1 , null ) )
936
- return ;
940
+ var success = CommitInternal ( out var actualTail , out var actualCommitNum , true , null , - 1 , null ) ;
937
941
938
- while ( CommittedUntilAddress < tailAddress || persistedCommitNum < actualCommitNum )
942
+ if ( success )
939
943
{
940
- var linkedCommitInfo = await task . WithCancellationAsync ( token ) . ConfigureAwait ( false ) ;
941
- task = linkedCommitInfo . NextTask ;
944
+ while ( CommittedUntilAddress < actualTail || persistedCommitNum < actualCommitNum )
945
+ {
946
+ var linkedCommitInfo = await task . WithCancellationAsync ( token ) . ConfigureAwait ( false ) ;
947
+ task = linkedCommitInfo . NextTask ;
948
+ }
949
+ }
950
+ else
951
+ {
952
+ while ( CommittedUntilAddress < tail || persistedCommitNum < lastCommit )
953
+ {
954
+ var linkedCommitInfo = await task . WithCancellationAsync ( token ) . ConfigureAwait ( false ) ;
955
+ task = linkedCommitInfo . NextTask ;
956
+ }
942
957
}
943
958
}
944
959
@@ -951,18 +966,37 @@ public async ValueTask CommitAsync(CancellationToken token = default)
951
966
public async ValueTask < Task < LinkedCommitInfo > > CommitAsync ( Task < LinkedCommitInfo > prevCommitTask , CancellationToken token = default )
952
967
{
953
968
token . ThrowIfCancellationRequested ( ) ;
969
+
970
+ // Take a lower-bound of the content of this commit in case our request is filtered but we need to spin
971
+ var tail = TailAddress ;
972
+ var lastCommit = commitNum ;
973
+
954
974
if ( prevCommitTask == null ) prevCommitTask = CommitTask ;
955
975
956
- if ( ! CommitInternal ( out var tailAddress , out var actualCommitNum , true , null , - 1 , null ) )
957
- return prevCommitTask ;
976
+ var success = CommitInternal ( out var actualTail , out var actualCommitNum , true , null , - 1 , null ) ;
958
977
959
- while ( CommittedUntilAddress < tailAddress || persistedCommitNum < actualCommitNum )
978
+
979
+ if ( success )
960
980
{
961
- var linkedCommitInfo = await prevCommitTask . WithCancellationAsync ( token ) . ConfigureAwait ( false ) ;
962
- if ( linkedCommitInfo . CommitInfo . UntilAddress < tailAddress || persistedCommitNum < actualCommitNum )
963
- prevCommitTask = linkedCommitInfo . NextTask ;
964
- else
965
- return linkedCommitInfo . NextTask ;
981
+ while ( CommittedUntilAddress < actualTail || persistedCommitNum < actualCommitNum )
982
+ {
983
+ var linkedCommitInfo = await prevCommitTask . WithCancellationAsync ( token ) . ConfigureAwait ( false ) ;
984
+ if ( linkedCommitInfo . CommitInfo . UntilAddress < actualTail || persistedCommitNum < actualCommitNum )
985
+ prevCommitTask = linkedCommitInfo . NextTask ;
986
+ else
987
+ return linkedCommitInfo . NextTask ;
988
+ }
989
+ }
990
+ else
991
+ {
992
+ while ( CommittedUntilAddress < tail || persistedCommitNum < lastCommit )
993
+ {
994
+ var linkedCommitInfo = await prevCommitTask . WithCancellationAsync ( token ) . ConfigureAwait ( false ) ;
995
+ if ( linkedCommitInfo . CommitInfo . UntilAddress < actualTail || persistedCommitNum < actualCommitNum )
996
+ prevCommitTask = linkedCommitInfo . NextTask ;
997
+ else
998
+ return linkedCommitInfo . NextTask ;
999
+ }
966
1000
}
967
1001
968
1002
return prevCommitTask ;
0 commit comments