tephra-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anew <...@git.apache.org>
Subject [GitHub] incubator-tephra pull request #22: Transaction pruning service
Date Thu, 08 Dec 2016 02:29:33 GMT
Github user anew commented on a diff in the pull request:

    https://github.com/apache/incubator-tephra/pull/22#discussion_r91430663
  
    --- Diff: tephra-core/src/main/java/org/apache/tephra/txprune/TransactionPruningRunnable.java
---
    @@ -0,0 +1,122 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.tephra.txprune;
    +
    +import org.apache.tephra.Transaction;
    +import org.apache.tephra.TransactionManager;
    +import org.apache.tephra.util.TxUtils;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.TreeSet;
    +
    +/**
    + * This class executes one run of transaction pruning every time it is invoked.
    + * Typically, this class will be scheduled to run periodically.
    + */
    +public class TransactionPruningRunnable implements Runnable {
    +  private static final Logger LOG = LoggerFactory.getLogger(TransactionPruningRunnable.class);
    +
    +  private final TransactionManager txManager;
    +  private final Map<String, TransactionPruningPlugin> plugins;
    +  private final long txMaxLifetimeMillis;
    +
    +  public TransactionPruningRunnable(TransactionManager txManager, Map<String, TransactionPruningPlugin>
plugins,
    +                                    long txMaxLifetimeMillis) {
    +    this.txManager = txManager;
    +    this.plugins = plugins;
    +    this.txMaxLifetimeMillis = txMaxLifetimeMillis;
    +  }
    +
    +  @Override
    +  public void run() {
    +    try {
    +      // TODO: TEPHRA-159 Start a read only transaction here
    +      Transaction tx = txManager.startShort();
    +      txManager.abort(tx);
    +
    +      long now = System.currentTimeMillis();
    +      long inactiveTransactionBound = TxUtils.getPruneUpperBound(tx, txMaxLifetimeMillis,
now);
    +      LOG.info("Starting invalid prune run for time {} and inactive transaction bound
{}",
    +               now, inactiveTransactionBound);
    +
    +      List<Long> pruneUpperBounds = new ArrayList<>();
    +      for (Map.Entry<String, TransactionPruningPlugin> entry : plugins.entrySet())
{
    +        String name = entry.getKey();
    +        TransactionPruningPlugin plugin = entry.getValue();
    +        try {
    +          LOG.debug("Fetching prune upper bound using plugin {}", name);
    +          long pruneUpperBound = plugin.fetchPruneUpperBound(now, inactiveTransactionBound);
    +          LOG.debug("Got prune upper bound {} from plugin {}", pruneUpperBound, name);
    +          pruneUpperBounds.add(pruneUpperBound);
    +        } catch (Exception e) {
    +          LOG.error("Aborting invalid prune run for time {} due to exception from plugin
{}", now, name, e);
    +          return;
    +        }
    +      }
    +
    +      long minPruneUpperBound = Collections.min(pruneUpperBounds);
    +      LOG.info("Got minimum prune upper bound {} across all plugins", minPruneUpperBound);
    +      if (minPruneUpperBound <= 0) {
    +        LOG.info("Not pruning invalid list since minimum prune upper bound ({}) is less
than 1", minPruneUpperBound);
    +        return;
    +      }
    +
    +      long[] invalids = tx.getInvalids();
    +      TreeSet<Long> toTruncate = new TreeSet<>();
    +      LOG.debug("Invalid list: {}", invalids);
    +      for (long invalid : invalids) {
    +        if (invalid <= minPruneUpperBound) {
    +          toTruncate.add(invalid);
    --- End diff --
    
    do we have to compute this list? Or can the txManager simply remove all transactions that
are older than the minPruneUpperBound?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message