Skip to content

Commit 400d705

Browse files
committed
Updated redo snippets to avoid extensive calling of countRedoRecords()
1 parent 1a47fe7 commit 400d705

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

csharp/snippets/redo/LoadWithRedoViaLoop/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@
109109
}
110110

111111
// now that we have loaded the records, check for redos and handle them
112-
while (engine.CountRedoRecords() > 0)
112+
for (string redo = engine.GetRedoRecord();
113+
redo != null;
114+
redo = engine.GetRedoRecord())
113115
{
114-
// get the next redo record
115-
string redo = engine.GetRedoRecord();
116-
117116
try
118117
{
119118
// process the redo record

csharp/snippets/redo/RedoContinuousViaFutures/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ TaskScheduler taskScheduler
116116
} while (pendingFutures.Count >= MaximumBacklog);
117117

118118
// check if there are no redo records right now
119+
// NOTE: we do NOT want to call countRedoRecords() in a loop that
120+
// is processing redo records, we call it here AFTER we believe
121+
// have processed all pending redos to confirm still zero
119122
if (engine.CountRedoRecords() == 0)
120123
{
121124
OutputRedoStatistics();

java/snippets/redo/LoadWithRedoViaLoop.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public static void main(String[] args) {
9898
}
9999

100100
// now that we have loaded the records, check for redos and handle them
101-
while (engine.countRedoRecords() > 0) {
102-
// get the next redo record
103-
String redo = engine.getRedoRecord();
104-
101+
for (String redo = engine.getRedoRecord();
102+
redo != null;
103+
redo = engine.getRedoRecord())
104+
{
105105
try {
106106
// process the redo record
107107
engine.processRedoRecord(redo, SZ_NO_FLAGS);

java/snippets/redo/RedoContinuousViaFutures.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public static void main(String[] args) {
103103
} while (pendingFutures.size() >= MAXIMUM_BACKLOG);
104104

105105
// check if there are no redo records right now
106+
// NOTE: we do NOT want to call countRedoRecords() in a loop that
107+
// is processing redo records, we call it here AFTER we believe
108+
// have processed all pending redos to confirm still zero
106109
if (engine.countRedoRecords() == 0) {
107110
outputRedoStatistics();
108111
System.out.println();

0 commit comments

Comments
 (0)