Skip to content

Conversation

@dengzhhu653
Copy link
Member

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

No

How was this patch tested?

https://ci.hive.apache.org/job/hive-flaky-check/915

Copy link
Member

@deniskuzZ deniskuzZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comments

@sonarqubecloud
Copy link

public enum TTYPE {
HOUSEKEEPING(new TableName(Warehouse.DEFAULT_CATALOG_NAME, "__METASTORE_LEADER_ELECTION__",
"metastore_housekeeping"), "housekeeping"),
WORKER(new TableName(Warehouse.DEFAULT_CATALOG_NAME, "__METASTORE_LEADER_ELECTION__",
Copy link
Member

@deniskuzZ deniskuzZ Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! we forgot to drop this

listenerMap.entrySet()) {
List<LeadershipStateListener> listenerList = entry.getValue();
List<TTYPE> ttypes = new ArrayList<>(listeners.keySet());
Collections.shuffle(ttypes);
Copy link
Member

@deniskuzZ deniskuzZ Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to shuffle?

MetastoreConf.setVar(conf, ConfVars.METASTORE_HOUSEKEEPING_LEADER_HOSTNAME, leaderHostName);
MetastoreConf.setVar(conf, ConfVars.METASTORE_HOUSEKEEPING_LEADER_ELECTION,
configuredLeader ? "host" : "lock");
leaderHostName != null ? "host" : "lock");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please try use enum (i.e Method from LeaderElectionFactory)

wait(service, flag1, flag2);
// now instance1 lease is timeout, the instance2 should be leader now
instance1.close();
synchronized (flag2) {
Copy link
Member

@deniskuzZ deniskuzZ Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need synchronized here? AtomicBoolean is designed for lock-free atomic updates.

while (!flag2.get()) {
    Thread.onSpinWait(); // JDK 9+
}

private static final Logger LOG = LoggerFactory.getLogger(LeaseLeaderElection.class);

private static final AtomicLong ID = new AtomicLong();
protected static final AtomicLong ID = new AtomicLong();
Copy link
Member

@deniskuzZ deniskuzZ Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't it be better if we expose protected fields via getters?

Copy link
Member

@deniskuzZ deniskuzZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1, some minor suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants