Skip to content

Commit 7cd6f0b

Browse files
committed
feat(core): release disk space faster on table drop
1 parent a800ac5 commit 7cd6f0b

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

core/src/main/java/io/questdb/cairo/CairoEngine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,8 @@ public TableToken lockTableName(CharSequence tableName, String dirName, int tabl
11941194

11951195
public boolean notifyDropped(TableToken tableToken) {
11961196
if (tableNameRegistry.dropTable(tableToken)) {
1197+
readerPool.notifyDropped(tableToken);
1198+
walWriterPool.notifyDropped(tableToken);
11971199
final MatViewRefreshTask matViewRefreshTask = tlMatViewRefreshTask.get();
11981200
matViewRefreshTask.clear();
11991201
matViewRefreshTask.baseTableToken = tableToken;

core/src/main/java/io/questdb/cairo/pool/AbstractMultiTenantPool.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ public boolean lock(TableToken tableToken) {
159159
return true;
160160
}
161161

162+
public void notifyDropped(TableToken token) {
163+
Entry<T> e = entries.get(token.getDirName());
164+
long thread = Thread.currentThread().getId();
165+
while (e != null) {
166+
for (int i = 0; i < ENTRY_SIZE; i++) {
167+
if (Unsafe.cas(e.allocations, i, UNALLOCATED, thread)) {
168+
// check if deadline violation still holds
169+
closeTenant(thread, e, i, PoolListener.EV_EXPIRE, PoolConstants.CR_IDLE);
170+
Unsafe.arrayPutOrdered(e.allocations, i, UNALLOCATED);
171+
}
172+
}
173+
e = e.next;
174+
}
175+
}
176+
162177
public void removeThreadLocalPoolSupervisor() {
163178
this.threadLocalPoolSupervisor.remove();
164179
}

core/src/main/java/io/questdb/cairo/pool/PoolConstants.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,21 @@
2626

2727
public final class PoolConstants {
2828
public static final int CR_DISTRESSED = 5;
29+
public static final int CR_DROPPED = 6;
2930
public static final int CR_IDLE = 3;
3031
public static final int CR_NAME_LOCK = 2;
3132
public static final int CR_POOL_CLOSE = 1;
3233
public static final int CR_REOPEN = 4;
3334

3435
public static String closeReasonText(int reason) {
35-
switch (reason) {
36-
case CR_POOL_CLOSE:
37-
return "POOL_CLOSED";
38-
case CR_NAME_LOCK:
39-
return "LOCKED";
40-
case CR_IDLE:
41-
return "IDLE";
42-
case CR_REOPEN:
43-
return "REOPEN";
44-
case CR_DISTRESSED:
45-
return "DISTRESSED";
46-
default:
47-
return "UNKNOWN";
48-
}
36+
return switch (reason) {
37+
case CR_POOL_CLOSE -> "POOL_CLOSED";
38+
case CR_NAME_LOCK -> "LOCKED";
39+
case CR_IDLE -> "IDLE";
40+
case CR_REOPEN -> "REOPEN";
41+
case CR_DISTRESSED -> "DISTRESSED";
42+
case CR_DROPPED -> "DROPPED";
43+
default -> "UNKNOWN";
44+
};
4945
}
5046
}

0 commit comments

Comments
 (0)