use of org.apache.ignite.spi.checkpoint.CheckpointListener in project ignite by apache.
the class SharedFsTimeoutTask method body.
/**
* {@inheritDoc}
*/
@Override
public void body() throws InterruptedException {
long nextTime = 0;
Collection<String> rmvKeys = new HashSet<>();
while (!isInterrupted()) {
rmvKeys.clear();
synchronized (mux) {
// nextTime is 0 only on first iteration.
if (nextTime != 0) {
long delay;
if (nextTime == -1)
delay = 5000;
else {
assert nextTime > 0;
delay = nextTime - U.currentTimeMillis();
}
while (delay > 0) {
mux.wait(delay);
delay = nextTime - U.currentTimeMillis();
}
}
Map<File, SharedFsTimeData> snapshot = new HashMap<>(files);
long now = U.currentTimeMillis();
nextTime = -1;
// if (now - last modification date) > expiration time
for (Map.Entry<File, SharedFsTimeData> entry : snapshot.entrySet()) {
File file = entry.getKey();
SharedFsTimeData timeData = entry.getValue();
try {
if (timeData.getLastAccessTime() != file.lastModified())
timeData.setExpireTime(SharedFsUtils.read(file, marshaller, log).getExpireTime());
} catch (IgniteCheckedException e) {
U.error(log, "Failed to marshal/unmarshal in checkpoint file: " + file.getAbsolutePath(), e);
continue;
} catch (IOException e) {
if (!file.exists()) {
files.remove(file);
rmvKeys.add(timeData.getKey());
} else
U.error(log, "Failed to read checkpoint file: " + file.getAbsolutePath(), e);
continue;
}
if (timeData.getExpireTime() > 0)
if (timeData.getExpireTime() <= now)
if (!file.delete() && file.exists())
U.error(log, "Failed to delete check point file by timeout: " + file.getAbsolutePath());
else {
files.remove(file);
rmvKeys.add(timeData.getKey());
if (log.isDebugEnabled())
log.debug("File was deleted by timeout: " + file.getAbsolutePath());
}
else if (timeData.getExpireTime() < nextTime || nextTime == -1)
nextTime = timeData.getExpireTime();
}
}
CheckpointListener lsnr = this.lsnr;
if (lsnr != null)
for (String key : rmvKeys) lsnr.onCheckpointRemoved(key);
}
synchronized (mux) {
files.clear();
}
}
use of org.apache.ignite.spi.checkpoint.CheckpointListener in project ignite by apache.
the class JdbcCheckpointSpi method removeExpiredCheckpoints.
/**
* Removes expired checkpoints from the checkpoint table.
*
* @param conn Active database connection.
* @return Number of removed expired checkpoints.
* @throws SQLException Thrown in case of any errors.
*/
private int removeExpiredCheckpoints(Connection conn) throws SQLException {
int delCnt = 0;
PreparedStatement selSt = null;
PreparedStatement delSt = null;
ResultSet rs = null;
Time time = new Time(U.currentTimeMillis());
CheckpointListener tmp = lsnr;
try {
if (tmp != null) {
selSt = conn.prepareStatement(selExpSql);
selSt.setTime(1, time);
rs = selSt.executeQuery();
while (rs.next()) tmp.onCheckpointRemoved(rs.getString(1));
}
delSt = conn.prepareStatement(delExpSql);
delSt.setTime(1, time);
delCnt = delSt.executeUpdate();
} finally {
U.close(rs, log);
U.close(selSt, log);
U.close(delSt, log);
}
if (log.isDebugEnabled())
log.debug("Successfully removed expired checkpoints from: " + tblName);
return delCnt;
}
Aggregations