You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/11/25 20:55:13 UTC
[GitHub] [hive] belugabehr opened a new pull request #1710: HIVE-24432: Delete Notification Events in Batches
belugabehr opened a new pull request #1710:
URL: https://github.com/apache/hive/pull/1710
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr commented on pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr commented on pull request #1710:
URL: https://github.com/apache/hive/pull/1710#issuecomment-738326173
@nrg4878 Review please for HMS work?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r540980013
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
Review comment:
Will do in separate JIRA after this new code gets some usage.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] aasha commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r539130987
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
Review comment:
The same improvement of deleting in batches can be applied to cleanWriteNotificationEvents also.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr closed pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr closed pull request #1710:
URL: https://github.com/apache/hive/pull/1710
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] aasha commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r539040762
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
- boolean commited = false;
- Query query = null;
+ final int eventBatchSize = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
+
+ final long ageSec = olderThan;
+ final Instant now = Instant.now();
+
+ final int tooOld = Math.toIntExact(now.getEpochSecond() - ageSec);
+
+ final Optional<Integer> batchSize = (eventBatchSize > 0) ? Optional.of(eventBatchSize) : Optional.empty();
+
+ final long start = System.nanoTime();
+ int deleteCount = doCleanNotificationEvents(tooOld, batchSize);
+
+ if (deleteCount == 0) {
+ LOG.info("No Notification events found to be cleaned with eventTime < {}", tooOld);
+ } else {
+ int batchCount = 0;
+ do {
+ batchCount = doCleanNotificationEvents(tooOld, batchSize);
+ deleteCount += batchCount;
+ } while (batchCount > 0);
+ }
+
+ final long finish = System.nanoTime();
+
+ LOG.info("Deleted {} notification events older than epoch:{} in {}ms", deleteCount, tooOld,
+ TimeUnit.NANOSECONDS.toMillis(finish - start));
+ }
+
+ private int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize) {
+ final Transaction tx = pm.currentTransaction();
+ int eventsCount = 0;
+
try {
- openTransaction();
- long tmp = System.currentTimeMillis() / 1000 - olderThan;
- int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp;
- query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld");
- query.declareParameters("java.lang.Integer tooOld");
+ tx.begin();
- int max_events = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
- max_events = max_events > 0 ? max_events : Integer.MAX_VALUE;
- query.setRange(0, max_events);
- query.setOrdering("eventId ascending");
+ try (Query query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld")) {
+ query.declareParameters("java.lang.Integer tooOld");
+ query.setOrdering("eventId ascending");
+ if (batchSize.isPresent()) {
+ query.setRange(0, batchSize.get());
+ }
- List<MNotificationLog> toBeRemoved = (List) query.execute(tooOld);
- int iteration = 0;
- int eventCount = 0;
- long minEventId = 0;
- long minEventTime = 0;
- long maxEventId = 0;
- long maxEventTime = 0;
- while (CollectionUtils.isNotEmpty(toBeRemoved)) {
- int listSize = toBeRemoved.size();
- if (iteration == 0) {
- MNotificationLog firstNotification = toBeRemoved.get(0);
- minEventId = firstNotification.getEventId();
- minEventTime = firstNotification.getEventTime();
+ List<MNotificationLog> events = (List) query.execute(ageSec);
+ if (CollectionUtils.isNotEmpty(events)) {
+ eventsCount = events.size();
+
+ if (LOG.isDebugEnabled()) {
+ int minEventTime, maxEventTime;
+ long minEventId, maxEventId;
+ Iterator<MNotificationLog> iter = events.iterator();
+ MNotificationLog firstNotification = iter.next();
+
+ minEventTime = maxEventTime = firstNotification.getEventTime();
+ minEventId = maxEventId = firstNotification.getEventId();
+
+ while (iter.hasNext()) {
+ MNotificationLog notification = iter.next();
Review comment:
Is the comparison required? events will always be in ascending order of event id
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] aasha edited a comment on pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
aasha edited a comment on pull request #1710:
URL: https://github.com/apache/hive/pull/1710#issuecomment-741558077
Please add a test.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr merged pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr merged pull request #1710:
URL: https://github.com/apache/hive/pull/1710
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r540981739
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
- boolean commited = false;
- Query query = null;
+ final int eventBatchSize = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
+
+ final long ageSec = olderThan;
+ final Instant now = Instant.now();
+
+ final int tooOld = Math.toIntExact(now.getEpochSecond() - ageSec);
+
+ final Optional<Integer> batchSize = (eventBatchSize > 0) ? Optional.of(eventBatchSize) : Optional.empty();
+
+ final long start = System.nanoTime();
+ int deleteCount = doCleanNotificationEvents(tooOld, batchSize);
+
+ if (deleteCount == 0) {
+ LOG.info("No Notification events found to be cleaned with eventTime < {}", tooOld);
+ } else {
+ int batchCount = 0;
+ do {
+ batchCount = doCleanNotificationEvents(tooOld, batchSize);
+ deleteCount += batchCount;
+ } while (batchCount > 0);
+ }
+
+ final long finish = System.nanoTime();
+
+ LOG.info("Deleted {} notification events older than epoch:{} in {}ms", deleteCount, tooOld,
+ TimeUnit.NANOSECONDS.toMillis(finish - start));
+ }
+
+ private int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize) {
+ final Transaction tx = pm.currentTransaction();
+ int eventsCount = 0;
+
try {
- openTransaction();
- long tmp = System.currentTimeMillis() / 1000 - olderThan;
- int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp;
- query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld");
- query.declareParameters("java.lang.Integer tooOld");
+ tx.begin();
- int max_events = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
- max_events = max_events > 0 ? max_events : Integer.MAX_VALUE;
- query.setRange(0, max_events);
- query.setOrdering("eventId ascending");
+ try (Query query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld")) {
+ query.declareParameters("java.lang.Integer tooOld");
+ query.setOrdering("eventId ascending");
+ if (batchSize.isPresent()) {
+ query.setRange(0, batchSize.get());
+ }
- List<MNotificationLog> toBeRemoved = (List) query.execute(tooOld);
- int iteration = 0;
- int eventCount = 0;
- long minEventId = 0;
- long minEventTime = 0;
- long maxEventId = 0;
- long maxEventTime = 0;
- while (CollectionUtils.isNotEmpty(toBeRemoved)) {
- int listSize = toBeRemoved.size();
- if (iteration == 0) {
- MNotificationLog firstNotification = toBeRemoved.get(0);
- minEventId = firstNotification.getEventId();
- minEventTime = firstNotification.getEventTime();
+ List<MNotificationLog> events = (List) query.execute(ageSec);
+ if (CollectionUtils.isNotEmpty(events)) {
+ eventsCount = events.size();
+
+ if (LOG.isDebugEnabled()) {
+ int minEventTime, maxEventTime;
+ long minEventId, maxEventId;
+ Iterator<MNotificationLog> iter = events.iterator();
+ MNotificationLog firstNotification = iter.next();
+
+ minEventTime = maxEventTime = firstNotification.getEventTime();
+ minEventId = maxEventId = firstNotification.getEventId();
+
+ while (iter.hasNext()) {
+ MNotificationLog notification = iter.next();
Review comment:
Hey, so this goes back to the discussion I had over here... PR #1728
There is really no guarantee that the eventTime is always increasing. So, the ID is always increasing, but if the min/max eventTime are to be discovered for each batch, then it needs to iterate. I'm happy to remove the logging and remove the iteration, but that was already in place and I didn't want to remove.
Edit: This is an out-of-band process that doesn't block anything else, so a few extra CPU cycles isn't the end of the world.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] pvargacl commented on pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
pvargacl commented on pull request #1710:
URL: https://github.com/apache/hive/pull/1710#issuecomment-738719330
LGTM +1 (non-binding)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r540984939
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
- boolean commited = false;
- Query query = null;
+ final int eventBatchSize = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
+
+ final long ageSec = olderThan;
+ final Instant now = Instant.now();
+
+ final int tooOld = Math.toIntExact(now.getEpochSecond() - ageSec);
+
+ final Optional<Integer> batchSize = (eventBatchSize > 0) ? Optional.of(eventBatchSize) : Optional.empty();
+
+ final long start = System.nanoTime();
+ int deleteCount = doCleanNotificationEvents(tooOld, batchSize);
+
+ if (deleteCount == 0) {
+ LOG.info("No Notification events found to be cleaned with eventTime < {}", tooOld);
+ } else {
+ int batchCount = 0;
+ do {
+ batchCount = doCleanNotificationEvents(tooOld, batchSize);
+ deleteCount += batchCount;
+ } while (batchCount > 0);
+ }
+
+ final long finish = System.nanoTime();
+
+ LOG.info("Deleted {} notification events older than epoch:{} in {}ms", deleteCount, tooOld,
+ TimeUnit.NANOSECONDS.toMillis(finish - start));
+ }
+
+ private int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize) {
+ final Transaction tx = pm.currentTransaction();
+ int eventsCount = 0;
+
try {
- openTransaction();
- long tmp = System.currentTimeMillis() / 1000 - olderThan;
- int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp;
- query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld");
- query.declareParameters("java.lang.Integer tooOld");
+ tx.begin();
- int max_events = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
- max_events = max_events > 0 ? max_events : Integer.MAX_VALUE;
- query.setRange(0, max_events);
- query.setOrdering("eventId ascending");
+ try (Query query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld")) {
+ query.declareParameters("java.lang.Integer tooOld");
+ query.setOrdering("eventId ascending");
+ if (batchSize.isPresent()) {
+ query.setRange(0, batchSize.get());
+ }
- List<MNotificationLog> toBeRemoved = (List) query.execute(tooOld);
- int iteration = 0;
- int eventCount = 0;
- long minEventId = 0;
- long minEventTime = 0;
- long maxEventId = 0;
- long maxEventTime = 0;
- while (CollectionUtils.isNotEmpty(toBeRemoved)) {
- int listSize = toBeRemoved.size();
- if (iteration == 0) {
- MNotificationLog firstNotification = toBeRemoved.get(0);
- minEventId = firstNotification.getEventId();
- minEventTime = firstNotification.getEventTime();
+ List<MNotificationLog> events = (List) query.execute(ageSec);
+ if (CollectionUtils.isNotEmpty(events)) {
+ eventsCount = events.size();
+
+ if (LOG.isDebugEnabled()) {
+ int minEventTime, maxEventTime;
+ long minEventId, maxEventId;
+ Iterator<MNotificationLog> iter = events.iterator();
+ MNotificationLog firstNotification = iter.next();
+
+ minEventTime = maxEventTime = firstNotification.getEventTime();
+ minEventId = maxEventId = firstNotification.getEventId();
+
+ while (iter.hasNext()) {
+ MNotificationLog notification = iter.next();
Review comment:
If you are speaking about the eventId portion only, then yes, one could look at the first and last item. Since the list needs to be iterated anyway, might as well just keep it simple and consistent with regards to how min/max is determined.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] aasha commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r539130987
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
Review comment:
The same improvement done in cleanNotificationEvents can be applied to cleanWriteNotificationEvents also.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] aasha commented on pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
aasha commented on pull request #1710:
URL: https://github.com/apache/hive/pull/1710#issuecomment-741558077
Please add a test. The code looks good to me.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] aasha commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r539040762
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
- boolean commited = false;
- Query query = null;
+ final int eventBatchSize = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
+
+ final long ageSec = olderThan;
+ final Instant now = Instant.now();
+
+ final int tooOld = Math.toIntExact(now.getEpochSecond() - ageSec);
+
+ final Optional<Integer> batchSize = (eventBatchSize > 0) ? Optional.of(eventBatchSize) : Optional.empty();
+
+ final long start = System.nanoTime();
+ int deleteCount = doCleanNotificationEvents(tooOld, batchSize);
+
+ if (deleteCount == 0) {
+ LOG.info("No Notification events found to be cleaned with eventTime < {}", tooOld);
+ } else {
+ int batchCount = 0;
+ do {
+ batchCount = doCleanNotificationEvents(tooOld, batchSize);
+ deleteCount += batchCount;
+ } while (batchCount > 0);
+ }
+
+ final long finish = System.nanoTime();
+
+ LOG.info("Deleted {} notification events older than epoch:{} in {}ms", deleteCount, tooOld,
+ TimeUnit.NANOSECONDS.toMillis(finish - start));
+ }
+
+ private int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize) {
+ final Transaction tx = pm.currentTransaction();
+ int eventsCount = 0;
+
try {
- openTransaction();
- long tmp = System.currentTimeMillis() / 1000 - olderThan;
- int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp;
- query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld");
- query.declareParameters("java.lang.Integer tooOld");
+ tx.begin();
- int max_events = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
- max_events = max_events > 0 ? max_events : Integer.MAX_VALUE;
- query.setRange(0, max_events);
- query.setOrdering("eventId ascending");
+ try (Query query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld")) {
+ query.declareParameters("java.lang.Integer tooOld");
+ query.setOrdering("eventId ascending");
+ if (batchSize.isPresent()) {
+ query.setRange(0, batchSize.get());
+ }
- List<MNotificationLog> toBeRemoved = (List) query.execute(tooOld);
- int iteration = 0;
- int eventCount = 0;
- long minEventId = 0;
- long minEventTime = 0;
- long maxEventId = 0;
- long maxEventTime = 0;
- while (CollectionUtils.isNotEmpty(toBeRemoved)) {
- int listSize = toBeRemoved.size();
- if (iteration == 0) {
- MNotificationLog firstNotification = toBeRemoved.get(0);
- minEventId = firstNotification.getEventId();
- minEventTime = firstNotification.getEventTime();
+ List<MNotificationLog> events = (List) query.execute(ageSec);
+ if (CollectionUtils.isNotEmpty(events)) {
+ eventsCount = events.size();
+
+ if (LOG.isDebugEnabled()) {
+ int minEventTime, maxEventTime;
+ long minEventId, maxEventId;
+ Iterator<MNotificationLog> iter = events.iterator();
+ MNotificationLog firstNotification = iter.next();
+
+ minEventTime = maxEventTime = firstNotification.getEventTime();
+ minEventId = maxEventId = firstNotification.getEventId();
+
+ while (iter.hasNext()) {
+ MNotificationLog notification = iter.next();
Review comment:
comparison is not required. events will always be in ascending order of event id
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr closed pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr closed pull request #1710:
URL: https://github.com/apache/hive/pull/1710
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r541149698
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
- boolean commited = false;
- Query query = null;
+ final int eventBatchSize = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
+
+ final long ageSec = olderThan;
+ final Instant now = Instant.now();
+
+ final int tooOld = Math.toIntExact(now.getEpochSecond() - ageSec);
+
+ final Optional<Integer> batchSize = (eventBatchSize > 0) ? Optional.of(eventBatchSize) : Optional.empty();
+
+ final long start = System.nanoTime();
+ int deleteCount = doCleanNotificationEvents(tooOld, batchSize);
+
+ if (deleteCount == 0) {
+ LOG.info("No Notification events found to be cleaned with eventTime < {}", tooOld);
+ } else {
+ int batchCount = 0;
+ do {
+ batchCount = doCleanNotificationEvents(tooOld, batchSize);
+ deleteCount += batchCount;
+ } while (batchCount > 0);
+ }
+
+ final long finish = System.nanoTime();
+
+ LOG.info("Deleted {} notification events older than epoch:{} in {}ms", deleteCount, tooOld,
+ TimeUnit.NANOSECONDS.toMillis(finish - start));
+ }
+
+ private int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize) {
+ final Transaction tx = pm.currentTransaction();
+ int eventsCount = 0;
+
try {
- openTransaction();
- long tmp = System.currentTimeMillis() / 1000 - olderThan;
- int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp;
- query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld");
- query.declareParameters("java.lang.Integer tooOld");
+ tx.begin();
- int max_events = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
- max_events = max_events > 0 ? max_events : Integer.MAX_VALUE;
- query.setRange(0, max_events);
- query.setOrdering("eventId ascending");
+ try (Query query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld")) {
+ query.declareParameters("java.lang.Integer tooOld");
+ query.setOrdering("eventId ascending");
+ if (batchSize.isPresent()) {
+ query.setRange(0, batchSize.get());
+ }
- List<MNotificationLog> toBeRemoved = (List) query.execute(tooOld);
- int iteration = 0;
- int eventCount = 0;
- long minEventId = 0;
- long minEventTime = 0;
- long maxEventId = 0;
- long maxEventTime = 0;
- while (CollectionUtils.isNotEmpty(toBeRemoved)) {
- int listSize = toBeRemoved.size();
- if (iteration == 0) {
- MNotificationLog firstNotification = toBeRemoved.get(0);
- minEventId = firstNotification.getEventId();
- minEventTime = firstNotification.getEventTime();
+ List<MNotificationLog> events = (List) query.execute(ageSec);
+ if (CollectionUtils.isNotEmpty(events)) {
+ eventsCount = events.size();
+
+ if (LOG.isDebugEnabled()) {
+ int minEventTime, maxEventTime;
+ long minEventId, maxEventId;
+ Iterator<MNotificationLog> iter = events.iterator();
+ MNotificationLog firstNotification = iter.next();
+
+ minEventTime = maxEventTime = firstNotification.getEventTime();
+ minEventId = maxEventId = firstNotification.getEventId();
+
+ while (iter.hasNext()) {
+ MNotificationLog notification = iter.next();
Review comment:
@aasha I updated existing unit tests to enforce small batch sizes (size = 1) so that when it deletes records, it does so in batches of 1.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr commented on a change in pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #1710:
URL: https://github.com/apache/hive/pull/1710#discussion_r540981739
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -10800,53 +10801,89 @@ public void addNotificationEvent(NotificationEvent entry) throws MetaException {
@Override
public void cleanNotificationEvents(int olderThan) {
- boolean commited = false;
- Query query = null;
+ final int eventBatchSize = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
+
+ final long ageSec = olderThan;
+ final Instant now = Instant.now();
+
+ final int tooOld = Math.toIntExact(now.getEpochSecond() - ageSec);
+
+ final Optional<Integer> batchSize = (eventBatchSize > 0) ? Optional.of(eventBatchSize) : Optional.empty();
+
+ final long start = System.nanoTime();
+ int deleteCount = doCleanNotificationEvents(tooOld, batchSize);
+
+ if (deleteCount == 0) {
+ LOG.info("No Notification events found to be cleaned with eventTime < {}", tooOld);
+ } else {
+ int batchCount = 0;
+ do {
+ batchCount = doCleanNotificationEvents(tooOld, batchSize);
+ deleteCount += batchCount;
+ } while (batchCount > 0);
+ }
+
+ final long finish = System.nanoTime();
+
+ LOG.info("Deleted {} notification events older than epoch:{} in {}ms", deleteCount, tooOld,
+ TimeUnit.NANOSECONDS.toMillis(finish - start));
+ }
+
+ private int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize) {
+ final Transaction tx = pm.currentTransaction();
+ int eventsCount = 0;
+
try {
- openTransaction();
- long tmp = System.currentTimeMillis() / 1000 - olderThan;
- int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp;
- query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld");
- query.declareParameters("java.lang.Integer tooOld");
+ tx.begin();
- int max_events = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
- max_events = max_events > 0 ? max_events : Integer.MAX_VALUE;
- query.setRange(0, max_events);
- query.setOrdering("eventId ascending");
+ try (Query query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld")) {
+ query.declareParameters("java.lang.Integer tooOld");
+ query.setOrdering("eventId ascending");
+ if (batchSize.isPresent()) {
+ query.setRange(0, batchSize.get());
+ }
- List<MNotificationLog> toBeRemoved = (List) query.execute(tooOld);
- int iteration = 0;
- int eventCount = 0;
- long minEventId = 0;
- long minEventTime = 0;
- long maxEventId = 0;
- long maxEventTime = 0;
- while (CollectionUtils.isNotEmpty(toBeRemoved)) {
- int listSize = toBeRemoved.size();
- if (iteration == 0) {
- MNotificationLog firstNotification = toBeRemoved.get(0);
- minEventId = firstNotification.getEventId();
- minEventTime = firstNotification.getEventTime();
+ List<MNotificationLog> events = (List) query.execute(ageSec);
+ if (CollectionUtils.isNotEmpty(events)) {
+ eventsCount = events.size();
+
+ if (LOG.isDebugEnabled()) {
+ int minEventTime, maxEventTime;
+ long minEventId, maxEventId;
+ Iterator<MNotificationLog> iter = events.iterator();
+ MNotificationLog firstNotification = iter.next();
+
+ minEventTime = maxEventTime = firstNotification.getEventTime();
+ minEventId = maxEventId = firstNotification.getEventId();
+
+ while (iter.hasNext()) {
+ MNotificationLog notification = iter.next();
Review comment:
Hey, so this goes back to the discussion I had over here... PR #1728
There is really no guarantee that the eventTime is always increasing. So, the ID is always increasing, but if the min/max eventTime are to be discovered for each batch, then it needs to iterate. I'm happy to remove the logging and remove the iteration, but that was already in place and I didn't want to remove.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] belugabehr closed pull request #1710: HIVE-24432: Delete Notification Events in Batches
Posted by GitBox <gi...@apache.org>.
belugabehr closed pull request #1710:
URL: https://github.com/apache/hive/pull/1710
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org