-
Notifications
You must be signed in to change notification settings - Fork 912
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
add async or sync for :ledger metadata index's rocksdb write #3368
Closed
StevenLuMT
wants to merge
8
commits into
apache:master
from
StevenLuMT:master_entryMetadataIndexSync
Closed
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
336f0a1
add async or sync for :ledger metadata index's rocksdb write
27341d0
checkstyle fixed
675d44b
Merge branch 'master' into master_entryMetadataIndexSync
StevenLuMT a12372f
Merge branch 'master' into master_entryMetadataIndexSync
StevenLuMT f7736a8
solve conflicts with the base branch
8ec4d5b
change sync type
1148a92
checkstyle fix
825296a
checkstyle fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...rver/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndexAsync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* | ||
* 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.bookkeeper.bookie.storage.ldb; | ||
|
||
import java.io.IOException; | ||
import java.util.Map.Entry; | ||
|
||
import org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorageDataFormats.LedgerData; | ||
import org.apache.bookkeeper.conf.ServerConfiguration; | ||
import org.apache.bookkeeper.stats.StatsLogger; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Maintains an index for the ledgers metadata. | ||
* | ||
* <p>Asynchronous write mode class, | ||
* the key is the ledgerId and the value is the {@link LedgerData} content. | ||
*/ | ||
public class LedgerMetadataIndexAsync extends LedgerMetadataIndex { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LedgerMetadataIndexAsync.class); | ||
|
||
public LedgerMetadataIndexAsync(ServerConfiguration conf, KeyValueStorageFactory storageFactory, String basePath, | ||
StatsLogger stats) throws IOException { | ||
super(conf, storageFactory, basePath, stats); | ||
} | ||
|
||
/** | ||
* Flushes all pending changes. | ||
*/ | ||
@Override | ||
public void flush() throws IOException { | ||
LongWrapper key = LongWrapper.get(); | ||
|
||
int updatedLedgers = 0; | ||
while (!pendingLedgersUpdates.isEmpty()) { | ||
Entry<Long, LedgerData> entry = pendingLedgersUpdates.poll(); | ||
key.set(entry.getKey()); | ||
byte[] value = entry.getValue().toByteArray(); | ||
ledgersDb.put(key.array, value); | ||
++updatedLedgers; | ||
} | ||
|
||
if (log.isDebugEnabled()) { | ||
log.debug("Persisting updates to {} ledgers", updatedLedgers); | ||
} | ||
|
||
ledgersDb.sync(); | ||
key.recycle(); | ||
} | ||
|
||
@Override | ||
public void removeDeletedLedgers() throws IOException { | ||
LongWrapper key = LongWrapper.get(); | ||
|
||
int deletedLedgers = 0; | ||
while (!pendingDeletedLedgers.isEmpty()) { | ||
long ledgerId = pendingDeletedLedgers.poll(); | ||
key.set(ledgerId); | ||
ledgersDb.delete(key.array); | ||
} | ||
|
||
if (log.isDebugEnabled()) { | ||
log.debug("Persisting deletes of ledgers {}", deletedLedgers); | ||
} | ||
|
||
ledgersDb.sync(); | ||
key.recycle(); | ||
} | ||
|
||
@Override | ||
boolean setStorageStateFlags(int expected, int newFlags) throws IOException { | ||
LongWrapper keyWrapper = LongWrapper.get(); | ||
LongWrapper currentWrapper = LongWrapper.get(); | ||
LongWrapper newFlagsWrapper = LongWrapper.get(); | ||
|
||
try { | ||
keyWrapper.set(STORAGE_FLAGS); | ||
newFlagsWrapper.set(newFlags); | ||
synchronized (ledgersDb) { | ||
int current = 0; | ||
if (ledgersDb.get(keyWrapper.array, currentWrapper.array) >= 0) { | ||
current = (int) currentWrapper.getValue(); | ||
} | ||
if (current == expected) { | ||
ledgersDb.put(keyWrapper.array, newFlagsWrapper.array); | ||
ledgersDb.sync(); | ||
return true; | ||
} | ||
} | ||
} finally { | ||
keyWrapper.recycle(); | ||
currentWrapper.recycle(); | ||
newFlagsWrapper.recycle(); | ||
} | ||
return false; | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
...erver/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndexSync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* | ||
* 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.bookkeeper.bookie.storage.ldb; | ||
|
||
import java.io.IOException; | ||
import java.util.Map.Entry; | ||
|
||
import org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorageDataFormats.LedgerData; | ||
import org.apache.bookkeeper.conf.ServerConfiguration; | ||
import org.apache.bookkeeper.stats.StatsLogger; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Maintains an index for the ledgers metadata. | ||
* | ||
* <p>Synchronous write mode class, | ||
* the key is the ledgerId and the value is the {@link LedgerData} content. | ||
*/ | ||
public class LedgerMetadataIndexSync extends LedgerMetadataIndex { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LedgerMetadataIndexSync.class); | ||
|
||
public LedgerMetadataIndexSync(ServerConfiguration conf, KeyValueStorageFactory storageFactory, String basePath, | ||
StatsLogger stats) throws IOException { | ||
super(conf, storageFactory, basePath, stats); | ||
} | ||
|
||
/** | ||
* Flushes all pending changes. | ||
*/ | ||
@Override | ||
public void flush() throws IOException { | ||
LongWrapper key = LongWrapper.get(); | ||
KeyValueStorage.Batch batch = ledgersDb.newBatch(); | ||
|
||
try { | ||
int updatedLedgers = 0; | ||
while (!pendingLedgersUpdates.isEmpty()) { | ||
Entry<Long, LedgerData> entry = pendingLedgersUpdates.poll(); | ||
key.set(entry.getKey()); | ||
byte[] value = entry.getValue().toByteArray(); | ||
batch.put(key.array, value); | ||
++updatedLedgers; | ||
} | ||
|
||
if (log.isDebugEnabled()) { | ||
log.debug("Persisting updates to {} ledgers", updatedLedgers); | ||
} | ||
} finally { | ||
try { | ||
batch.flush(); | ||
batch.clear(); | ||
} finally { | ||
key.recycle(); | ||
batch.close(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void removeDeletedLedgers() throws IOException { | ||
LongWrapper key = LongWrapper.get(); | ||
KeyValueStorage.Batch batch = ledgersDb.newBatch(); | ||
|
||
try { | ||
int deletedLedgers = 0; | ||
while (!pendingDeletedLedgers.isEmpty()) { | ||
long ledgerId = pendingDeletedLedgers.poll(); | ||
key.set(ledgerId); | ||
batch.remove(key.array); | ||
} | ||
|
||
if (log.isDebugEnabled()) { | ||
log.debug("Persisting deletes of ledgers {}", deletedLedgers); | ||
} | ||
} finally { | ||
try { | ||
batch.flush(); | ||
batch.clear(); | ||
} finally { | ||
key.recycle(); | ||
batch.close(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
boolean setStorageStateFlags(int expected, int newFlags) throws IOException { | ||
LongWrapper keyWrapper = LongWrapper.get(); | ||
LongWrapper currentWrapper = LongWrapper.get(); | ||
LongWrapper newFlagsWrapper = LongWrapper.get(); | ||
|
||
KeyValueStorage.Batch batch = ledgersDb.newBatch(); | ||
try { | ||
keyWrapper.set(STORAGE_FLAGS); | ||
newFlagsWrapper.set(newFlags); | ||
synchronized (ledgersDb) { | ||
int current = 0; | ||
if (ledgersDb.get(keyWrapper.array, currentWrapper.array) >= 0) { | ||
current = (int) currentWrapper.getValue(); | ||
} | ||
if (current == expected) { | ||
batch.put(keyWrapper.array, newFlagsWrapper.array); | ||
return true; | ||
} | ||
} | ||
} finally { | ||
try { | ||
batch.flush(); | ||
batch.clear(); | ||
} finally { | ||
keyWrapper.recycle(); | ||
currentWrapper.recycle(); | ||
newFlagsWrapper.recycle(); | ||
batch.close(); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems to be that synchronisation around
ledgersDb
is not consistent.sometimes we don't access the variable that way.
I wonder why spotbugs does not complain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic has not been updated, and the code to move according to #2936
It doesn't seem to be a problem, or if I modify synchronized to the method, I will make a unified correction to the historical code. @eolivelli