-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDDS-1391 : Add ability in OM to serve delta updates through an API. #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c2f2789
77c97f7
1f61132
9ad8123
631c6df
ac17863
6c858ba
8af6b15
4a8a0c9
071119d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.hadoop.utils.db; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Wrapper class to hold DB data read from the RocksDB log file. | ||
| */ | ||
| public class DBUpdatesWrapper { | ||
|
|
||
| private List<byte[]> dataList = new ArrayList<>(); | ||
| private long currentSequenceNumber = 0; | ||
|
|
||
| public void addWriteBatch(byte[] data, long sequenceNumber) { | ||
| dataList.add(data); | ||
| if (currentSequenceNumber < sequenceNumber) { | ||
| currentSequenceNumber = sequenceNumber; | ||
| } | ||
| } | ||
|
|
||
| public List<byte[]> getData() { | ||
| return dataList; | ||
| } | ||
|
|
||
| public long getCurrentSequenceNumber() { | ||
| return currentSequenceNumber; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.hadoop.utils.db; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Thrown if RocksDB is unable to find requested data from WAL file. | ||
| */ | ||
| public class DataNotFoundException extends IOException { | ||
|
avijayanhwx marked this conversation as resolved.
Outdated
|
||
|
|
||
| public DataNotFoundException() { | ||
| super(); | ||
| } | ||
|
|
||
| public DataNotFoundException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,8 @@ | |
| import org.rocksdb.FlushOptions; | ||
| import org.rocksdb.RocksDB; | ||
| import org.rocksdb.RocksDBException; | ||
| import org.rocksdb.TransactionLogIterator; | ||
| import org.rocksdb.WriteBatch; | ||
| import org.rocksdb.WriteOptions; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -318,6 +320,44 @@ public CodecRegistry getCodecRegistry() { | |
| return codecRegistry; | ||
| } | ||
|
|
||
| @Override | ||
| public DBUpdatesWrapper getUpdatesSince(long sequenceNumber) | ||
| throws DataNotFoundException { | ||
|
|
||
| DBUpdatesWrapper dbUpdatesWrapper = new DBUpdatesWrapper(); | ||
| try { | ||
| TransactionLogIterator transactionLogIterator = | ||
| db.getUpdatesSince(sequenceNumber); | ||
|
|
||
| boolean flag = true; | ||
|
avijayanhwx marked this conversation as resolved.
Outdated
|
||
|
|
||
| while (transactionLogIterator.isValid()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this imply flush to sst can happen while iterating the log?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, flushes can happen from memtables to SST anytime. If the WAL is deleted while it is being read, we will still be handle it through a retry mechanism from Recon side.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this means we need to at least configure the flushes defensively to maybe 3 * recon sync internal. Will that be a separate Jira or is already correctly configured? |
||
| TransactionLogIterator.BatchResult result = | ||
| transactionLogIterator.getBatch(); | ||
| long currSequenceNumber = result.sequenceNumber(); | ||
| if (flag && currSequenceNumber > 1 + sequenceNumber) { | ||
| throw new DataNotFoundException("Unable to read data from " + | ||
| "RocksDB wal to get delta updates. It may have already been" + | ||
| "flushed to SSTs."); | ||
| } | ||
| flag = false; | ||
|
avijayanhwx marked this conversation as resolved.
Outdated
|
||
| if (currSequenceNumber == sequenceNumber) { | ||
| transactionLogIterator.next(); | ||
| continue; | ||
| } | ||
| WriteBatch writeBatch = result.writeBatch(); | ||
| byte[] writeBatchData = writeBatch.data(); | ||
|
avijayanhwx marked this conversation as resolved.
Outdated
|
||
| dbUpdatesWrapper.addWriteBatch(writeBatchData, | ||
| result.sequenceNumber()); | ||
| transactionLogIterator.next(); | ||
| } | ||
| } catch (RocksDBException e) { | ||
| LOG.error("Unable to get delta updates since sequenceNumber {} ", | ||
| sequenceNumber, e); | ||
| } | ||
| return dbUpdatesWrapper; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public RocksDB getDb() { | ||
| return db; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.