This is an automated email from the ASF dual-hosted git repository.
dimas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 3d354f883 Remove PolarisCallContext from TreeMapMetaStore (#2195)
3d354f883 is described below
commit 3d354f883f56d810594e8b2c07a6ce543451765b
Author: Christopher Lambert <[email protected]>
AuthorDate: Wed Jul 30 23:37:54 2025 +0200
Remove PolarisCallContext from TreeMapMetaStore (#2195)
* remove PolarisCallContext from TreeMapMetaStore methods
* reset diagnosticServices in TreeMapMetaStore
* simplify ensure methods
---
.../transactional/TreeMapMetaStore.java | 61 +++++++++-------------
.../TreeMapTransactionalPersistenceImpl.java | 8 +--
2 files changed, 28 insertions(+), 41 deletions(-)
diff --git
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapMetaStore.java
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapMetaStore.java
index 7716b1ad1..81a0823e4 100644
---
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapMetaStore.java
+++
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapMetaStore.java
@@ -25,7 +25,6 @@ import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.function.Supplier;
-import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityCore;
@@ -69,7 +68,7 @@ public class TreeMapMetaStore {
* @param key key for that value
*/
public T read(String key) {
- TreeMapMetaStore.this.ensureReadTr();
+ ensureReadTr();
T value = this.slice.getOrDefault(key, null);
return (value != null) ? this.copyRecord.apply(value) : null;
}
@@ -80,7 +79,7 @@ public class TreeMapMetaStore {
* @param prefix key prefix
*/
public List<T> readRange(String prefix) {
- TreeMapMetaStore.this.ensureReadTr();
+ ensureReadTr();
if (prefix.isEmpty()) {
return new ArrayList<>(this.slice.values());
}
@@ -100,7 +99,7 @@ public class TreeMapMetaStore {
* @param value value to write
*/
public void write(T value) {
- TreeMapMetaStore.this.ensureReadWriteTr();
+ ensureReadWriteTr();
T valueToWrite = (value != null) ? this.copyRecord.apply(value) : null;
String key = this.buildKey(valueToWrite);
// write undo if needs be
@@ -116,7 +115,7 @@ public class TreeMapMetaStore {
* @param key key for the record to remove
*/
public void delete(String key) {
- TreeMapMetaStore.this.ensureReadWriteTr();
+ ensureReadWriteTr();
if (slice.containsKey(key)) {
// write undo if needs be
if (!this.undoSlice.containsKey(key)) {
@@ -132,7 +131,7 @@ public class TreeMapMetaStore {
* @param prefix key prefix for the record to remove
*/
public void deleteRange(String prefix) {
- TreeMapMetaStore.this.ensureReadWriteTr();
+ ensureReadWriteTr();
List<T> elements = this.readRange(prefix);
for (T element : elements) {
this.delete(element);
@@ -140,7 +139,7 @@ public class TreeMapMetaStore {
}
void deleteAll() {
- TreeMapMetaStore.this.ensureReadWriteTr();
+ ensureReadWriteTr();
slice.clear();
undoSlice.clear();
}
@@ -156,7 +155,7 @@ public class TreeMapMetaStore {
/** Rollback all changes made to this slice since transaction started */
private void rollback() {
- TreeMapMetaStore.this.ensureReadWriteTr();
+ ensureReadWriteTr();
undoSlice.forEach(
(key, value) -> {
if (value == null) {
@@ -194,6 +193,7 @@ public class TreeMapMetaStore {
private Transaction tr;
// diagnostic services
+ private final PolarisDiagnostics initialDiagnosticServices;
private PolarisDiagnostics diagnosticServices;
// all entities
@@ -301,6 +301,7 @@ public class TreeMapMetaStore {
policyMappingRecord.getTargetId()),
PolarisPolicyMappingRecord::new);
+ this.initialDiagnosticServices = diagnostics;
// no transaction open yet
this.diagnosticServices = diagnostics;
this.tr = null;
@@ -397,7 +398,7 @@ public class TreeMapMetaStore {
}
/** Ensure that a read/write FDB transaction has been started */
- public void ensureReadWriteTr() {
+ private void ensureReadWriteTr() {
this.diagnosticServices.check(
this.tr != null && this.tr.isWrite(), "no_write_transaction_started");
}
@@ -410,18 +411,16 @@ public class TreeMapMetaStore {
/**
* Run inside a read/write transaction
*
- * @param callCtx call context to use
- * @param transactionCode transaction code
* @return the result of the execution
*/
public <T> T runInTransaction(
- @Nonnull PolarisCallContext callCtx, @Nonnull Supplier<T>
transactionCode) {
+ @Nonnull PolarisDiagnostics diagnostics, @Nonnull Supplier<T>
transactionCode) {
synchronized (lock) {
// execute transaction
try {
// init diagnostic services
- this.diagnosticServices = callCtx.getDiagServices();
+ this.diagnosticServices = diagnostics;
this.startWriteTransaction();
return transactionCode.get();
} catch (Throwable e) {
@@ -431,26 +430,21 @@ public class TreeMapMetaStore {
throw e;
} finally {
this.tr = null;
- this.diagnosticServices = null;
+ this.diagnosticServices = this.initialDiagnosticServices;
}
}
}
- /**
- * Run inside a read/write transaction
- *
- * @param callCtx call context to use
- * @param transactionCode transaction code
- */
+ /** Run inside a read/write transaction */
public void runActionInTransaction(
- @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) {
+ @Nonnull PolarisDiagnostics diagnostics, @Nonnull Runnable
transactionCode) {
synchronized (lock) {
// execute transaction
try {
// init diagnostic services
- this.diagnosticServices = callCtx.getDiagServices();
+ this.diagnosticServices = diagnostics;
this.startWriteTransaction();
transactionCode.run();
} catch (Throwable e) {
@@ -460,7 +454,7 @@ public class TreeMapMetaStore {
throw e;
} finally {
this.tr = null;
- this.diagnosticServices = null;
+ this.diagnosticServices = this.initialDiagnosticServices;
}
}
}
@@ -468,46 +462,39 @@ public class TreeMapMetaStore {
/**
* Run inside a read only transaction
*
- * @param callCtx call context to use
- * @param transactionCode transaction code
* @return the result of the execution
*/
public <T> T runInReadTransaction(
- @Nonnull PolarisCallContext callCtx, @Nonnull Supplier<T>
transactionCode) {
+ @Nonnull PolarisDiagnostics diagnostics, @Nonnull Supplier<T>
transactionCode) {
synchronized (lock) {
// execute transaction
try {
// init diagnostic services
- this.diagnosticServices = callCtx.getDiagServices();
+ this.diagnosticServices = diagnostics;
this.startReadTransaction();
return transactionCode.get();
} finally {
this.tr = null;
- this.diagnosticServices = null;
+ this.diagnosticServices = this.initialDiagnosticServices;
}
}
}
- /**
- * Run inside a read only transaction
- *
- * @param callCtx call context to use
- * @param transactionCode transaction code
- */
+ /** Run inside a read only transaction */
public void runActionInReadTransaction(
- @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) {
+ @Nonnull PolarisDiagnostics diagnostics, @Nonnull Runnable
transactionCode) {
synchronized (lock) {
// execute transaction
try {
// init diagnostic services
- this.diagnosticServices = callCtx.getDiagServices();
+ this.diagnosticServices = diagnostics;
this.startReadTransaction();
transactionCode.run();
} finally {
this.tr = null;
- this.diagnosticServices = null;
+ this.diagnosticServices = this.initialDiagnosticServices;
}
}
}
diff --git
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java
index 5ce0866c3..6ebb18e8c 100644
---
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java
+++
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java
@@ -79,7 +79,7 @@ public class TreeMapTransactionalPersistenceImpl extends
AbstractTransactionalPe
@Nonnull PolarisCallContext callCtx, @Nonnull Supplier<T>
transactionCode) {
// run transaction on our underlying store
- return store.runInTransaction(callCtx, transactionCode);
+ return store.runInTransaction(callCtx.getDiagServices(), transactionCode);
}
/** {@inheritDoc} */
@@ -88,7 +88,7 @@ public class TreeMapTransactionalPersistenceImpl extends
AbstractTransactionalPe
@Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) {
// run transaction on our underlying store
- store.runActionInTransaction(callCtx, transactionCode);
+ store.runActionInTransaction(callCtx.getDiagServices(), transactionCode);
}
/** {@inheritDoc} */
@@ -96,7 +96,7 @@ public class TreeMapTransactionalPersistenceImpl extends
AbstractTransactionalPe
public <T> T runInReadTransaction(
@Nonnull PolarisCallContext callCtx, @Nonnull Supplier<T>
transactionCode) {
// run transaction on our underlying store
- return store.runInReadTransaction(callCtx, transactionCode);
+ return store.runInReadTransaction(callCtx.getDiagServices(),
transactionCode);
}
/** {@inheritDoc} */
@@ -105,7 +105,7 @@ public class TreeMapTransactionalPersistenceImpl extends
AbstractTransactionalPe
@Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) {
// run transaction on our underlying store
- store.runActionInReadTransaction(callCtx, transactionCode);
+ store.runActionInReadTransaction(callCtx.getDiagServices(),
transactionCode);
}
/**