keith-turner commented on code in PR #4439:
URL: https://github.com/apache/accumulo/pull/4439#discussion_r1569577537
##########
server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java:
##########
@@ -1551,40 +1569,88 @@ public enum RefreshPurpose {
MINC_COMPLETION, REFRESH_RPC, FLUSH_ID_UPDATE, LOAD
}
- public void refreshMetadata(RefreshPurpose refreshPurpose) {
+ public class RefreshSession {
+
+ private final long observedRefreshCount;
+
+ private RefreshSession(long observedRefreshCount) {
+ this.observedRefreshCount = observedRefreshCount;
+ }
+
+ /**
+ * Refresh tablet metadata using metadata that was read separately.
+ *
+ * @param tabletMetadata this tablet metadata must have been read after
calling
+ * {@link Tablet#startRefresh()}
+ */
+ public boolean refreshMetadata(RefreshPurpose refreshPurpose,
TabletMetadata tabletMetadata) {
+ return Tablet.this.refreshMetadata(refreshPurpose, observedRefreshCount,
tabletMetadata);
+ }
+ }
+
+ /**
+ * A refresh session allows code outside of this class to safely read tablet
metadata and pass it
+ * back. This is useful for the case where many tablets need to be refreshed
and we want to batch
+ * reading their metadata. Creating a refresh session will not block. A
refresh session is able to
+ * detect changes in tablet metadata that happen during its existence and
reread tablet metadata
+ * if necessary.
+ */
+ public RefreshSession startRefresh() {
+ return new RefreshSession(latestMetadata.get().refreshCount);
+ }
+
+ private boolean refreshMetadata(RefreshPurpose refreshPurpose, Long
observedRefreshCount,
+ TabletMetadata tabletMetadata) {
+
refreshLock.lock();
try {
+ var prevMetadata = latestMetadata.get();
+ // if the tablet metadata passed in is stale, then reread it
+ if (observedRefreshCount == null ||
!observedRefreshCount.equals(prevMetadata.refreshCount)) {
+ if (observedRefreshCount != null) {
+ log.debug(
+ "Metadata read outside of refresh lock is no longer valid,
rereading metadata. {} {} {}",
+ extent, observedRefreshCount, prevMetadata.refreshCount);
+ }
Review Comment:
Yeah that was the intention, but it did it in a really weird way. The code
could be more straightforward. I will update it.
--
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]