use of me.prettyprint.hector.api.beans.Row in project logprocessing by cloudian.
the class CDRDataAccess method deleteBeforeTS.
// Delete all entries before (and including) a particular hour timestamp.
// For the hourly timeline,
public void deleteBeforeTS(long hourStamp) {
String sLastHour = m_sdfHourly.format(new Date(hourStamp));
String strLastHourCompare = String.format("%013d", hourStamp);
// those columns.
try {
boolean bMoreRows = true;
String begRangeKey = "";
// Handle HourlyTimeline and CDREntry CFs first
while (bMoreRows) {
List<Row<String, String, String>> rows = m_daoHourlyTimeline.getRangeSlice(begRangeKey, sLastHour, "", LIMIT, false);
if (rows.size() > 0) {
Row<String, String, String> lastRow = rows.get(rows.size() - 1);
// Get start key for next range slice
begRangeKey = lastRow.getKey();
for (Row<String, String, String> row : rows) {
List<HColumn<String, String>> cols = row.getColumnSlice().getColumns();
for (HColumn<String, String> col : cols) {
String entryId = col.getValue();
// Delete individual CDR entry
m_daoCDREntry.delete(entryId, null, StringSerializer.get());
}
String hourKey = row.getKey();
// Delete entire row.
m_daoHourlyTimeline.delete(hourKey, null, StringSerializer.get());
}
if (rows.size() == 1) {
// this is the last row in the slice - data was already deleted.
bMoreRows = false;
}
} else {
// Done operating on rows for HourlyTimeline
bMoreRows = false;
}
}
// Now take care of MSISDNTimeline
bMoreRows = true;
begRangeKey = "";
while (bMoreRows) {
List<Row<String, String, String>> rows = m_daoMSISDNTimeline.getRangeSlice(begRangeKey, "", "", LIMIT, false);
if (rows.size() > 0) {
Row<String, String, String> lastRow = rows.get(rows.size() - 1);
// Get start key for next range slice
begRangeKey = lastRow.getKey();
for (Row<String, String, String> row : rows) {
List<HColumn<String, String>> cols = row.getColumnSlice().getColumns();
for (HColumn<String, String> col : cols) {
String colStamp = col.getName();
if (colStamp.compareTo(strLastHourCompare) < 0) {
// Lexicographic comparison - want to ignore the UUID portion of column name
// Delete MSISDNTimeline column
m_daoHourlyTimeline.delete(row.getKey(), colStamp, StringSerializer.get());
// TODO: Should we optimize to add all deletions for the row, and then execute??
}
}
}
if (rows.size() == 1) {
// this is the last row in the slice - data was already deleted.
bMoreRows = false;
}
} else {
// Done operating on rows for MSISDNTimeline
bMoreRows = false;
}
}
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}
Aggregations