Skip to content

Commit

Permalink
W-16093303: Implement staging file persisting metric name
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzxu-crm committed Jun 28, 2024
1 parent 1b49d7e commit 4cd4bc4
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ public Metric forId( long metricId )
return getMetric( metricId );
}

@Override
public Metric forName( String metricName )
{
return getMetric( metricName );
}

@Override
public void dumpStats()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
package com.demandware.carbonj.service.db.model;

@FunctionalInterface
public interface MetricProvider
{
Metric forId(long metricId);
Metric forName(String metricName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ public void dumpStats()
received.getCount(), drop.getCount(), saved.getCount()));
}

public void add( String dbName, int from, long metricId, double val )
public void add( String dbName, int from, long metricId, double val, String metricName )
{
received.mark();

StagingFileSet stagingFile = stagingFileSetProvider.get( dbName, from );
StagingFileRecord r = new StagingFileRecord( stagingFile, metricId, DataPoint.strValue(val) );
StagingFileRecord r = new StagingFileRecord( stagingFile, metricId, DataPoint.strValue(val), metricName );

if ( queue.offer( r ) ) //TODO: slow down instead of dropping?
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private void updateLowerResolutionArchive( Metric metric, int ts, double val, Re
// from also identifies interval in nextArchive for this data point
int from = nextPolicy.interval( ts );
if (stagingStore != null) {
stagingStore.add(dbName, from, metric.id, val);
stagingStore.add(dbName, from, metric.id, val, metric.name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public Optional<IntervalValues> loadNeighbours()
}

long metricId = r.metricId;
String metricName = r.metricName;
List<Double> vals = new ArrayList<>();

while ( true )
Expand All @@ -136,7 +137,12 @@ public Optional<IntervalValues> loadNeighbours()
r = nextRecord();
}

Metric m = metricProvider.forId( metricId );
Metric m;
if (metricName == null) {
m = metricProvider.forId(metricId);
} else {
m = metricProvider.forName(metricName);
}
if( m == null )
{
throw new RuntimeException(String.format("Failed to find metric with metricId [%s].", metricId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public synchronized boolean write( StagingFileRecord r )
bw.append( String.valueOf( r.metricId ) );
bw.write( " " );
bw.write( r.strValue );
bw.write( " " );
bw.write( r.metricName );
bw.write( "\n");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public class StagingFileRecord
public final StagingFileSet fileName;
public final long metricId;
public final String strValue;
public final String metricName;

StagingFileRecord( StagingFileSet fileName, long metricId, String strValue)
StagingFileRecord( StagingFileSet fileName, long metricId, String strValue, String metricName)
{
this.fileName = fileName;
this.metricId = metricId;
this.strValue = strValue;
this.metricName = metricName;
}

StagingFileRecord( StagingFileSet fileName, String line)
Expand All @@ -27,10 +29,16 @@ public class StagingFileRecord
int idStart = 0;
int idEnd = line.indexOf( ' ' );

int valueStart = idEnd + 1;

metricId = Long.parseLong( line.substring( idStart, idEnd ) );
strValue = line.substring( valueStart );
idStart = idEnd + 1;
idEnd = line.indexOf(' ', idStart);
if (idEnd < 0) {
strValue = line.substring(idStart);
metricName = null;
} else {
strValue = line.substring(idStart, idEnd);
metricName = line.substring(idEnd + 1);
}
}

double val()
Expand All @@ -45,6 +53,7 @@ public String toString()
"fileName=" + fileName +
", metricId=" + metricId +
", strValue='" + strValue + '\'' +
", metricName=" + metricName +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ public void write(StagingFileRecord r)
private StagingFile reopen( StagingFileSet fs, int seq)
{
File f = new File( dir, fs.nameForUnsorted(fs.id, seq) );
Preconditions.checkState( f.exists() );
StagingFile sf = new StagingFile(metricRegistry, f, sort, metricProvider, fs.dbName);
sf.open();
return sf;
return openStagingFile(f, fs.dbName);
}

private StagingFile open(StagingFileSet fs)
{
File f = new File( dir, fs.getNextUnsortedFileName( dir ) );
return openStagingFile(f, fs.dbName);
}

private StagingFile openStagingFile(File f, String dbName) {
Preconditions.checkState( !f.exists() );
StagingFile sf = new StagingFile(metricRegistry, f, sort, metricProvider, fs.dbName);
StagingFile sf = new StagingFile(metricRegistry, f, sort, metricProvider, dbName);
sf.open();
return sf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SystemSort implements StagingFilesSort

private final long timeoutInSeconds;

private long bufSizeKb = 256000;
private long bufSizeKb = 1048576;
private String tmpDir = "/tmp";
private int parallel = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,13 @@ public Metric forId(long metricId) {
Collections.emptyList(),
Collections.emptyList());
}

@Override
public Metric forName(String metricName) {
return new Metric(metricName, 1,
new AggregationPolicy(AggregationMethod.AVG, 1, null),
Collections.emptyList(),
Collections.emptyList());
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=1.1.55-SNAPSHOT
version=1.1.55-W-16093303
org.gradle.jvmargs=--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED
org.gradle.daemon=true
ccGradlePluginVersion=3.0.3
Expand Down

0 comments on commit 4cd4bc4

Please sign in to comment.