Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* This file is part of VoltDB.
* Copyright (C) 2008-2020 VoltDB Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VoltDB. If not, see .
*/
package org.voltdb;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.hsqldb_voltpatches.TimeToLiveVoltDB;
import org.hsqldb_voltpatches.lib.StringUtil;
import org.voltcore.logging.Level;
import org.voltcore.logging.VoltLogger;
import org.voltcore.utils.CoreUtils;
import org.voltdb.VoltTable.ColumnInfo;
import org.voltdb.catalog.Table;
import org.voltdb.catalog.TimeToLive;
import org.voltdb.client.ClientResponse;
import org.voltdb.client.ProcedureCallback;
import org.voltdb.iv2.MpTransactionState;
import org.voltdb.utils.CatalogUtil;
//schedule and process time-to-live feature via @LowImpactDeleteNT. The host with smallest host id
//will get the task done.
public class TTLManager extends StatsSource{
//exception is thrown if DR consumer gets a chunk of larger than 50MB
//DRTupleStream.cpp
public static final String DR_LIMIT_MSG = "bytes exceeds max DR Buffer size";
static final int DELAY = Integer.getInteger("TIME_TO_LIVE_DELAY", 0) * 1000;
static final int INTERVAL = Integer.getInteger("TIME_TO_LIVE_INTERVAL", 1000);
static final int CHUNK_SIZE = Integer.getInteger("TIME_TO_LIVE_CHUNK_SIZE", 1000);
static final int TIMEOUT = Integer.getInteger("TIME_TO_LIVE_TIMEOUT", 2000);
public static final int NT_PROC_TIMEOUT = Integer.getInteger("NT_PROC_TIMEOUT", 1000 * 120);
static final int LOG_SUPPRESSION_INTERVAL_SECONDS = 60;
public static class TTLStats {
final String tableName;
long rowsLeft = 0L;
//Total rows deleted on this TTL control. The total count
//will be reset if this node fails and another node takes over
//TTL control
long rowsDeleted = 0L;
long rowsLastDeleted = 0L;
Timestamp ts;
public TTLStats(String tableName) {
this.tableName = tableName;
}
public void update(long rowDeleted, long rowsLeft, long lastExecutionTimestamp) {
this.rowsLastDeleted = rowDeleted;
this.rowsLeft = rowsLeft;
this.rowsDeleted += rowDeleted;
ts = new Timestamp(lastExecutionTimestamp);
}
@Override
public String toString() {
return String.format("TTL stats on table %s: tuples deleted %d, tuples remaining %d", tableName, rowsDeleted, rowsLeft);
}
}
public class TTLTask implements Runnable {
final String tableName;
final TTLStats stats;
AtomicReference ttlRef;
AtomicReference
tableRef;
AtomicBoolean canceled = new AtomicBoolean(false);
public TTLTask(String tableName, TimeToLive timeToLive, Table table, TTLStats ttlStats) {
this.tableName = tableName;
ttlRef = new AtomicReference<>(timeToLive);
tableRef = new AtomicReference<>(table);
stats = ttlStats;
}
@Override
public void run() {
//do not run TTL when cluster is paused to allow proper draining of stream and dr buffer
final VoltDBInterface voltdb = VoltDB.instance();
if (voltdb.getMode() != OperationMode.RUNNING) {
return;
}
ClientInterface cl = voltdb.getClientInterface();
if (!canceled.get() && cl != null && cl.isAcceptingConnections()) {
String stream = tableRef.get().getMigrationtarget();
if (!StringUtil.isEmpty(stream)) {
migrate(cl, this);
} else {
delete(cl, this);
}
}
}
public void cancel() {
canceled.set(true);
ScheduledFuture> fut = m_futures.get(tableName);
if (fut != null) {
fut.cancel(true);
m_futures.remove(tableName);
}
}
public void updateTask(TimeToLive updatedTTL, Table updatedTable) {
ttlRef.compareAndSet(ttlRef.get(), updatedTTL);
tableRef.compareAndSet(tableRef.get(), updatedTable);
}
long getValue() {
TimeToLive ttl = ttlRef.get();
if (VoltType.get((byte)ttl.getTtlcolumn().getType()) != VoltType.TIMESTAMP) {
return ttl.getTtlvalue();
}
TimeUnit timeUnit = TimeUnit.SECONDS;
if(!ttl.getTtlunit().isEmpty()) {
final char frequencyUnit = ttl.getTtlunit().toLowerCase().charAt(0);
switch (frequencyUnit) {
case 'm':
timeUnit = TimeUnit.MINUTES;
break;
case 'h':
timeUnit = TimeUnit.HOURS;
break;
case 'd':
timeUnit = TimeUnit.DAYS;
break;
default:
timeUnit = TimeUnit.SECONDS;
}
}
return ((System.currentTimeMillis() - timeUnit.toMillis(ttl.getTtlvalue())) * 1000);
}
int getMaxFrequency() {
return ttlRef.get().getMaxfrequency();
}
int getBatchSize() {
return ttlRef.get().getBatchsize();
}
String getColumnName() {
return ttlRef.get().getTtlcolumn().getName();
}
String getStream() {
return tableRef.get().getMigrationtarget();
}
}
private static class DummyIterator implements Iterator