AmatyaAvadhanula commented on code in PR #16393:
URL: https://github.com/apache/druid/pull/16393#discussion_r1591830566
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java:
##########
@@ -1271,6 +1278,138 @@ public void remove(final Task task)
}
}
+ /**
+ * Acquire a read lock to perform the segment transactional append action
for a given datasource.
+ * Also verifies that all the locks are of the type APPEND for the task.
+ * @param task task to perform the append action
+ */
+ public void acquireTransactionalAppendLock(Task task)
+ {
+ acquireTransactionalAppendLock(task, LOCK_ACQUIRE_TIMEOUT_MILLIS);
+ }
+
+ @VisibleForTesting
+ void acquireTransactionalAppendLock(Task task, long lockAcquireTimeoutMillis)
Review Comment:
Made this public instead
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java:
##########
@@ -1271,6 +1278,138 @@ public void remove(final Task task)
}
}
+ /**
+ * Acquire a read lock to perform the segment transactional append action
for a given datasource.
+ * Also verifies that all the locks are of the type APPEND for the task.
+ * @param task task to perform the append action
+ */
+ public void acquireTransactionalAppendLock(Task task)
+ {
+ acquireTransactionalAppendLock(task, LOCK_ACQUIRE_TIMEOUT_MILLIS);
+ }
+
+ @VisibleForTesting
+ void acquireTransactionalAppendLock(Task task, long lockAcquireTimeoutMillis)
+ {
+ for (TaskLockPosse lockPosse : findLockPossesForTask(task)) {
+ if (lockPosse.taskLock.getType() != TaskLockType.APPEND) {
+ throw new ISE(
+ "All the locks must be of type APPEND for
segmentTransactionalAppend. Found lock of type[%s] for task[%s].",
+ lockPosse.taskLock.getType(), task.getId()
+ );
+ }
+ }
+ final String datasource = task.getDataSource();
+ giant.lock();
+ try {
+ final boolean acquired = datasourceToConcurrentLock
+ .computeIfAbsent(datasource, ds -> new ReentrantReadWriteLock())
+ .readLock()
+ .tryLock(lockAcquireTimeoutMillis, TimeUnit.MILLISECONDS);
+ if (!acquired) {
+ throw new ISE("Timed out while acquiring transactional append lock for
datasource[%s].", datasource);
+ }
+ datasourceToNumActiveLocks.put(
+ datasource,
+ datasourceToNumActiveLocks.getOrDefault(datasource, 0) + 1
+ );
+ }
+ catch (InterruptedException e) {
+ throw new ISE(e, "Interrupted while acquiring transactional append lock
for datasource[%s].", datasource);
+ }
+ finally {
+ giant.unlock();
+ }
+ }
+
+ /**
+ * Acquire a write lock to perform the segment transactional replace action
for a given datasource.
+ * Also verifies that all the locks are of the type REPLACE for the task.
+ * @param task task to perform the replace action
+ */
+ public void acquireTransactionalReplaceLock(Task task)
+ {
+ acquireTransactionalReplaceLock(task, LOCK_ACQUIRE_TIMEOUT_MILLIS);
+ }
+
+ @VisibleForTesting
+ void acquireTransactionalReplaceLock(Task task, long
lockAcquireTimeoutMillis)
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]