Skip to content

Commit 07b6c79

Browse files
Merge branch 'develop' of https://github.com/tronprotocol/java-tron into develop
2 parents 11cb514 + d54b55c commit 07b6c79

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

src/main/java/org/tron/storage/leveldb/LevelDbDataSourceImpl.java

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
*/
1515
package org.tron.storage.leveldb;
16+
1617
import org.iq80.leveldb.*;
1718
import org.slf4j.Logger;
1819
import org.slf4j.LoggerFactory;
@@ -47,7 +48,6 @@ public class LevelDbDataSourceImpl implements DbSourceInter<byte[]> {
4748
boolean alive;
4849

4950

50-
5151
private ReadWriteLock resetDbLock = new ReentrantReadWriteLock();
5252

5353
public LevelDbDataSourceImpl() {
@@ -143,14 +143,11 @@ public String getDBName() {
143143
@Override
144144
public byte[] getData(byte[] key) {
145145
resetDbLock.readLock().lock();
146-
147-
try {
148-
return database.get(key);
149-
} catch (DBException e) {
150-
byte[] ret = database.get(key);
151-
return ret;
152-
}
153-
finally {
146+
try {
147+
return database.get(key);
148+
} catch (DBException e) {
149+
return database.get(key);
150+
} finally {
154151
resetDbLock.readLock().unlock();
155152
}
156153
}
@@ -178,17 +175,14 @@ public void deleteData(byte[] key) {
178175
@Override
179176
public Set<byte[]> allKeys() {
180177
resetDbLock.readLock().lock();
181-
try {
182-
try (DBIterator iterator = database.iterator()) {
183-
Set<byte[]> result = new HashSet<>();
184-
for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
185-
result.add(iterator.peekNext().getKey());
186-
}
187-
188-
return result;
189-
} catch (IOException e) {
190-
throw new RuntimeException(e);
178+
try (DBIterator iterator = database.iterator()) {
179+
Set<byte[]> result = new HashSet<>();
180+
for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
181+
result.add(iterator.peekNext().getKey());
191182
}
183+
return result;
184+
} catch (IOException e) {
185+
throw new RuntimeException(e);
192186
} finally {
193187
resetDbLock.readLock().unlock();
194188
}
@@ -211,14 +205,12 @@ private void updateByBatchInner(Map<byte[], byte[]> rows) throws Exception {
211205
public void updateByBatch(Map<byte[], byte[]> rows) {
212206
resetDbLock.readLock().lock();
213207
try {
208+
updateByBatchInner(rows);
209+
} catch (Exception e) {
214210
try {
215211
updateByBatchInner(rows);
216-
} catch (Exception e) {
217-
try {
218-
updateByBatchInner(rows);
219-
} catch (Exception e1) {
220-
throw new RuntimeException(e);
221-
}
212+
} catch (Exception e1) {
213+
throw new RuntimeException(e);
222214
}
223215
} finally {
224216
resetDbLock.readLock().unlock();
@@ -233,15 +225,12 @@ public boolean flush() {
233225
@Override
234226
public void closeDB() {
235227
resetDbLock.writeLock().lock();
228+
if (!isAlive()) return;
236229
try {
237-
if (!isAlive()) return;
238-
239-
try {
240-
database.close();
241-
alive = false;
242-
} catch (IOException e) {
243-
logger.error("Failed to find the dbStore file on the closeDB: {} ", dataBaseName);
244-
}
230+
database.close();
231+
alive = false;
232+
} catch (IOException e) {
233+
logger.error("Failed to find the dbStore file on the closeDB: {} ", dataBaseName);
245234
} finally {
246235
resetDbLock.writeLock().unlock();
247236
}

0 commit comments

Comments
 (0)