Skip to content

Commit e70aeb4

Browse files
HDDS-1601. Implement updating lastAppliedIndex after buffer flush to OM DB. (#972)
1 parent 8370a0a commit e70aeb4

File tree

5 files changed

+81
-5
lines changed

5 files changed

+81
-5
lines changed

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerDoubleBuffer.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,23 @@ public class OzoneManagerDoubleBuffer {
6464
private final AtomicLong flushIterations = new AtomicLong(0);
6565
private volatile boolean isRunning;
6666

67+
private final OzoneManagerRatisSnapshot ozoneManagerRatisSnapShot;
6768

68-
public OzoneManagerDoubleBuffer(OMMetadataManager omMetadataManager) {
69+
public OzoneManagerDoubleBuffer(OMMetadataManager omMetadataManager,
70+
OzoneManagerRatisSnapshot ozoneManagerRatisSnapShot) {
6971
this.currentBuffer = new ConcurrentLinkedQueue<>();
7072
this.readyBuffer = new ConcurrentLinkedQueue<>();
7173
this.omMetadataManager = omMetadataManager;
7274

75+
this.ozoneManagerRatisSnapShot = ozoneManagerRatisSnapShot;
76+
7377
isRunning = true;
7478
// Daemon thread which runs in back ground and flushes transactions to DB.
7579
daemon = new Daemon(this::flushTransactions);
7680
daemon.setName("OMDoubleBufferFlushThread");
7781
daemon.start();
7882

83+
7984
}
8085

8186
/**
@@ -117,7 +122,13 @@ private void flushTransactions() {
117122
readyBuffer.clear();
118123
// cleanup cache.
119124
cleanupCache(lastRatisTransactionIndex);
120-
// TODO: update the last updated index in OzoneManagerStateMachine.
125+
126+
// TODO: Need to revisit this logic, once we have multiple
127+
// executors for volume/bucket request handling. As for now
128+
// transactions are serialized this should be fine.
129+
// update the last updated index in OzoneManagerStateMachine.
130+
ozoneManagerRatisSnapShot.updateLastAppliedIndex(
131+
lastRatisTransactionIndex);
121132
}
122133
} catch (InterruptedException ex) {
123134
Thread.currentThread().interrupt();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with this
4+
* work for additional information regarding copyright ownership. The ASF
5+
* licenses this file to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* <p>
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
* <p>
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.om.ratis;
19+
20+
/**
21+
* Functional interface for OM RatisSnapshot.
22+
*/
23+
24+
public interface OzoneManagerRatisSnapshot {
25+
26+
/**
27+
* Update lastAppliedIndex with the specified value in OzoneManager
28+
* StateMachine.
29+
* @param lastAppliedIndex
30+
*/
31+
void updateLastAppliedIndex(long lastAppliedIndex);
32+
}

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public OzoneManagerStateMachine(OzoneManagerRatisServer ratisServer) {
7575
this.omRatisServer = ratisServer;
7676
this.ozoneManager = omRatisServer.getOzoneManager();
7777
this.ozoneManagerDoubleBuffer =
78-
new OzoneManagerDoubleBuffer(ozoneManager.getMetadataManager());
78+
new OzoneManagerDoubleBuffer(ozoneManager.getMetadataManager(),
79+
this::updateLastAppliedIndex);
7980
this.handler = new OzoneManagerHARequestHandlerImpl(ozoneManager,
8081
ozoneManagerDoubleBuffer);
8182
}
@@ -375,6 +376,11 @@ private Message runCommand(OMRequest request, long trxLogIndex) {
375376
return OMRatisHelper.convertResponseToMessage(response);
376377
}
377378

379+
@SuppressWarnings("HiddenField")
380+
public void updateLastAppliedIndex(long lastAppliedIndex) {
381+
this.lastAppliedIndex = lastAppliedIndex;
382+
}
383+
378384
/**
379385
* Submits read request to OM and returns the response Message.
380386
* @param request OMRequest

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithDummyResponse.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class TestOzoneManagerDoubleBufferWithDummyResponse {
5555
private OMMetadataManager omMetadataManager;
5656
private OzoneManagerDoubleBuffer doubleBuffer;
5757
private AtomicLong trxId = new AtomicLong(0);
58+
private OzoneManagerRatisSnapshot ozoneManagerRatisSnapshot;
59+
private long lastAppliedIndex;
60+
5861

5962
@Rule
6063
public TemporaryFolder folder = new TemporaryFolder();
@@ -66,7 +69,11 @@ public void setup() throws IOException {
6669
folder.newFolder().getAbsolutePath());
6770
omMetadataManager =
6871
new OmMetadataManagerImpl(configuration);
69-
doubleBuffer = new OzoneManagerDoubleBuffer(omMetadataManager);
72+
ozoneManagerRatisSnapshot = index -> {
73+
lastAppliedIndex = index;
74+
};
75+
doubleBuffer = new OzoneManagerDoubleBuffer(omMetadataManager,
76+
ozoneManagerRatisSnapshot);
7077
}
7178

7279
@After
@@ -94,6 +101,9 @@ public void testDoubleBufferWithDummyResponse() throws Exception {
94101
Assert.assertTrue(omMetadataManager.countRowsInTable(
95102
omMetadataManager.getBucketTable()) == (bucketCount));
96103
Assert.assertTrue(doubleBuffer.getFlushIterations() > 0);
104+
105+
// Check lastAppliedIndex is updated correctly or not.
106+
Assert.assertEquals(bucketCount, lastAppliedIndex);
97107
}
98108

99109
/**

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithOMResponse.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public class TestOzoneManagerDoubleBufferWithOMResponse {
6565
private OMMetadataManager omMetadataManager;
6666
private OzoneManagerDoubleBuffer doubleBuffer;
6767
private AtomicLong trxId = new AtomicLong(0);
68+
private OzoneManagerRatisSnapshot ozoneManagerRatisSnapshot;
69+
private long lastAppliedIndex;
6870

6971
@Rule
7072
public TemporaryFolder folder = new TemporaryFolder();
@@ -76,7 +78,11 @@ public void setup() throws IOException {
7678
folder.newFolder().getAbsolutePath());
7779
omMetadataManager =
7880
new OmMetadataManagerImpl(configuration);
79-
doubleBuffer = new OzoneManagerDoubleBuffer(omMetadataManager);
81+
ozoneManagerRatisSnapshot = index -> {
82+
lastAppliedIndex = index;
83+
};
84+
doubleBuffer = new OzoneManagerDoubleBuffer(omMetadataManager,
85+
ozoneManagerRatisSnapshot);
8086
}
8187

8288
@After
@@ -146,6 +152,9 @@ public void testDoubleBufferWithMixOfTransactions() throws Exception {
146152
checkCreateBuckets(bucketQueue);
147153

148154
checkDeletedBuckets(deleteBucketQueue);
155+
156+
// Check lastAppliedIndex is updated correctly or not.
157+
Assert.assertEquals(bucketCount + deleteCount + 1, lastAppliedIndex);
149158
}
150159

151160
/**
@@ -208,6 +217,9 @@ public void testDoubleBufferWithMixOfTransactionsParallel() throws Exception {
208217
checkCreateBuckets(bucketQueue);
209218

210219
checkDeletedBuckets(deleteBucketQueue);
220+
221+
// Check lastAppliedIndex is updated correctly or not.
222+
Assert.assertEquals(bucketCount + deleteCount + 2, lastAppliedIndex);
211223
}
212224

213225
/**
@@ -321,6 +333,8 @@ private void checkDeletedBuckets(Queue<OMBucketDeleteResponse>
321333
public void testDoubleBuffer(int iterations, int bucketCount)
322334
throws Exception {
323335
try {
336+
// Reset transaction id.
337+
trxId.set(0);
324338
// Calling setup and stop here because this method is called from a
325339
// single test multiple times.
326340
setup();
@@ -343,6 +357,9 @@ public void testDoubleBuffer(int iterations, int bucketCount)
343357
omMetadataManager.getBucketTable()) == (bucketCount) * iterations);
344358

345359
Assert.assertTrue(doubleBuffer.getFlushIterations() > 0);
360+
361+
// Check lastAppliedIndex is updated correctly or not.
362+
Assert.assertEquals((bucketCount + 1) * iterations, lastAppliedIndex);
346363
} finally {
347364
stop();
348365
}

0 commit comments

Comments
 (0)