Skip to content

Commit e3b50c4

Browse files
committed
TransactionLocking improvements
1 parent 33f848e commit e3b50c4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

engine/src/main/java/com/blobcity/db/locks/TransactionLocking.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.blobcity.db.locks;
1818

1919
import com.blobcity.db.exceptions.OperationException;
20+
21+
import java.util.HashMap;
2022
import java.util.Map;
2123
import java.util.concurrent.ConcurrentHashMap;
2224
import org.springframework.scheduling.annotation.Scheduled;
@@ -56,6 +58,7 @@ public void acquireLock(String app, String table, String pk, LockType lockType)
5658
return value;
5759
});
5860
map.get(key).acquireReadLock();
61+
break;
5962
case WRITE:
6063
map.compute(key, (k, value)-> {
6164
if(value == null) {
@@ -64,6 +67,7 @@ public void acquireLock(String app, String table, String pk, LockType lockType)
6467
return value;
6568
});
6669
map.get(key).acquireWriteLock();
70+
break;
6771
}
6872
}
6973

@@ -96,9 +100,6 @@ private String generateKey(String app, String table, String pk) {
96100
@Scheduled(cron = "0 * * * * *")
97101
private void cleanUp() {
98102
final long removeBefore = System.currentTimeMillis() - 30000; //30 seconds
99-
map.entrySet().removeIf(key -> {
100-
ReadWriteSemaphore rws = map.get(key);
101-
return rws.getLockType() == LockType.NONE && rws.getLastOperatedAt() < removeBefore;
102-
});
103+
map.entrySet().removeIf(item -> item.getValue().getLockType() == LockType.NONE && item.getValue().getLastOperatedAt() < removeBefore);
103104
}
104105
}

engine/src/main/java/com/blobcity/db/storage/BSqlFileManager.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ public class BSqlFileManager {
8787
*/
8888
public String select(final String app, final String table, final String key) throws OperationException {
8989
String result = null;
90-
if (LicenseRules.DATA_CACHING && cacheRules.shouldCache(app, table)) {
90+
if (app.equals(".systemdb") || (LicenseRules.DATA_CACHING && cacheRules.shouldCache(app, table))) {
9191
result = dataCache.load(app, table, key);
9292
if (result != null) {
9393
return result;
9494
}
9595
}
96-
9796
transactionLocking.acquireLock(app, table, key, LockType.READ);
9897
try {
9998
Path path = Paths.get(PathUtil.dataFile(app, table, key));
@@ -332,7 +331,7 @@ public void save(final String app, final String table, final String key, final S
332331
Path path = Paths.get(PathUtil.dataFile(app, table, key));
333332
try {
334333
Files.write(path, jsonString.getBytes("UTF-8"));
335-
if (LicenseRules.DATA_CACHING && cacheRules.shouldCache(app, table)) {
334+
if (app.equals(".systemdb") || (LicenseRules.DATA_CACHING && cacheRules.shouldCache(app, table))) {
336335
dataCache.cache(app, table, key, jsonString);
337336
}
338337
} catch (IOException ex) {
@@ -354,7 +353,7 @@ public void insert(final String app, final String table, final String key, final
354353
}
355354
try {
356355
Files.write(path, jsonString.getBytes("UTF-8"));
357-
if (LicenseRules.DATA_CACHING && LicenseRules.CACHE_INSERTS && cacheRules.shouldCache(app, table)) {
356+
if (app.equals(".systemdb") || (LicenseRules.DATA_CACHING && LicenseRules.CACHE_INSERTS && cacheRules.shouldCache(app, table))) {
358357
dataCache.cache(app, table, key, jsonString);
359358
}
360359
} catch (IOException ex) {
@@ -380,7 +379,7 @@ public boolean rename(final String app, final String table, final String existin
380379
if (file.renameTo(newFile)) {
381380

382381
/* Update cache */
383-
if (LicenseRules.DATA_CACHING && cacheRules.shouldCache(app, table)) {
382+
if (app.equals(".systemdb") || (LicenseRules.DATA_CACHING && cacheRules.shouldCache(app, table))) {
384383
String cachedValue = dataCache.load(app, table, existingKey);
385384
dataCache.invalidate(app, table, existingKey);
386385
dataCache.cache(app, table, newKey, cachedValue);

0 commit comments

Comments
 (0)