Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove CompactionQueue comparator #1645

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions src/core/CompactionQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final class CompactionQueue extends ConcurrentSkipListMap<byte[], Boolean> {
* @param tsdb The TSDB we belong to.
*/
public CompactionQueue(final TSDB tsdb) {
super(new Cmp(tsdb));
super();
this.tsdb = tsdb;
metric_width = tsdb.metrics.width();
flush_interval = tsdb.config.getInt("tsd.storage.compaction.flush_interval");
Expand Down Expand Up @@ -172,14 +172,10 @@ private Deferred<ArrayList<Object>> flush(final long cut_off, int maxflushes) {
final ArrayList<Deferred<Object>> ds =
new ArrayList<Deferred<Object>>(Math.min(maxflushes, max_concurrent_flushes));
int nflushes = 0;
int seed = (int) (System.nanoTime() % 3);
for (final byte[] row : this.keySet()) {
if (maxflushes == 0) {
if (maxflushes <= 0) {
break;
}
if (seed == row.hashCode() % 3) {
continue;
}
final long base_time = Bytes.getUnsignedInt(row,
Const.SALT_WIDTH() + metric_width);
if (base_time > cut_off) {
Expand Down Expand Up @@ -857,27 +853,4 @@ public void run() {
}
}
}

/**
* Helper to sort the byte arrays in the compaction queue.
* <p>
* This comparator sorts things by timestamp first, this way we can find
* all rows of the same age at once.
*/
private static final class Cmp implements Comparator<byte[]> {

/** The position with which the timestamp of metric starts. */
private final short timestamp_pos;

public Cmp(final TSDB tsdb) {
timestamp_pos = (short) (Const.SALT_WIDTH() + tsdb.metrics.width());
}

@Override
public int compare(final byte[] a, final byte[] b) {
final int c = Bytes.memcmp(a, b, timestamp_pos, Const.TIMESTAMP_BYTES);
// If the timestamps are equal, sort according to the entire row key.
return c != 0 ? c : Bytes.memcmp(a, b);
}
}
}