Skip to content

Commit 369d29a

Browse files
authored
Merge pull request #18 from salesforce/ash_remove_longId
Revert "Long metric id support"
2 parents bbc4652 + 73d0d3a commit 369d29a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+225
-982
lines changed

carbonj.service/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ RUN yum update -y && \
2323
sysstat \
2424
epel-release
2525

26+
RUN yum install -y gcc-c++ gcc make libtool automake autoconf make python3-devel
27+
2628
RUN rpm --import http://repos.azulsystems.com/RPM-GPG-KEY-azulsystems && \
2729
curl -o /etc/yum.repos.d/zulu.repo http://repos.azulsystems.com/rhel/zulu.repo && \
2830
yum update -y && \

carbonj.service/src/main/java/com/demandware/carbonj/service/admin/CarbonjAdmin.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.commons.lang3.StringUtils;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
29-
import org.springframework.beans.factory.annotation.Value;
3029
import org.springframework.http.HttpStatus;
3130
import org.springframework.stereotype.Controller;
3231
import org.springframework.web.bind.annotation.*;
@@ -60,10 +59,6 @@ public class CarbonjAdmin
6059

6160
private final NameUtils nameUtils;
6261

63-
@Value( "${metrics.store.longId:false}" )
64-
private boolean longId;
65-
66-
6762
private Supplier<RuntimeException> notConfigured = ( ) -> new RuntimeException(
6863
"Time Series Store is not configured." );
6964

@@ -125,7 +120,7 @@ public void listMetrics2( @PathVariable final String pattern, Writer response )
125120
}
126121

127122
@RequestMapping( value = "/dumpnames", method = RequestMethod.GET )
128-
public void dumpNames( @RequestParam( value = "startId", required = false, defaultValue = "0" ) long startId,
123+
public void dumpNames( @RequestParam( value = "startId", required = false, defaultValue = "0" ) int startId,
129124
@RequestParam( value = "startName", required = false ) String startName,
130125
@RequestParam( value = "count", required = false ) Integer count,
131126
@RequestParam( value = "filter", required = false ) String wildcard, Writer response )
@@ -143,7 +138,7 @@ public void dumpNames( @RequestParam( value = "startId", required = false, defau
143138
}
144139
try
145140
{
146-
tsStore().scanMetrics( startId, getMaxId(), m -> {
141+
tsStore().scanMetrics( startId, Integer.MAX_VALUE, m -> {
147142
if ( !filter.test( m ) )
148143
{
149144
return;
@@ -169,10 +164,6 @@ public void dumpNames( @RequestParam( value = "startId", required = false, defau
169164
}
170165
}
171166

172-
private long getMaxId() {
173-
return longId ? Long.MAX_VALUE : Integer.MAX_VALUE;
174-
}
175-
176167
private boolean loadLock = false;
177168

178169
private volatile boolean abortLoad = false;
@@ -537,7 +528,6 @@ static class StopException
537528

538529
static boolean hasDataSince( TimeSeriesStore ts, String metric, int from )
539530
{
540-
541531
for ( String dbName : Arrays.asList( "30m2y", "5m7d", "60s24h" ) )
542532
{
543533
if ( null != ts.getFirst( dbName, metric, from, Integer.MAX_VALUE ) )
@@ -564,7 +554,7 @@ public void cleanSeries( @RequestParam( value = "from", required = false, defaul
564554

565555
try
566556
{
567-
ts.scanMetrics( 0, getMaxId(), m -> {
557+
ts.scanMetrics( 0, Integer.MAX_VALUE, m -> {
568558
if ( written.get() >= count )
569559
{
570560
// produced big enough result - interrupt execution through exception (signal "donness")
@@ -632,7 +622,7 @@ public void dumpSeries( @PathVariable final String dbName,
632622
try
633623
{
634624
ts.scanMetrics( cursor,
635-
getMaxId(),
625+
Integer.MAX_VALUE,
636626
m -> {
637627
try
638628
{

carbonj.service/src/main/java/com/demandware/carbonj/service/db/TimeSeriesStore.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface TimeSeriesStore
3838

3939
DataPointExportResults exportPoints( String dbName, String metricName );
4040

41-
DataPointExportResults exportPoints( String dbName, long metricId );
41+
DataPointExportResults exportPoints( String dbName, int metricId );
4242

4343
// to support testing
4444
Metric selectRandomMetric();
@@ -47,13 +47,13 @@ public interface TimeSeriesStore
4747

4848
Metric getMetric( String name, boolean createIfMissing );
4949

50-
Metric getMetric( long metricId );
50+
Metric getMetric( int metricId );
5151

52-
String getMetricName( long metricId );
52+
String getMetricName( int metricId );
5353

5454
void scanMetrics( Consumer<Metric> m );
5555

56-
long scanMetrics( long start, long end, Consumer<Metric> m );
56+
int scanMetrics( int start, int end, Consumer<Metric> m );
5757

5858
List<Metric> findMetrics( String pattern );
5959

carbonj.service/src/main/java/com/demandware/carbonj/service/db/TimeSeriesStoreImpl.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ public class TimeSeriesStoreImpl implements TimeSeriesStore
105105

106106
private volatile long logNoOfSeriesThreshold;
107107

108-
private boolean longId;
109-
110108
public static ThreadPoolExecutor newSerialTaskQueue(int queueSize) {
111109
ThreadFactory tf =
112110
new ThreadFactoryBuilder()
@@ -144,8 +142,7 @@ public TimeSeriesStoreImpl(MetricRegistry metricRegistry, MetricIndex nameIndex,
144142
ThreadPoolExecutor heavyQueryTaskQueue, ThreadPoolExecutor serialTaskQueue,
145143
DataPointStore pointStore, DatabaseMetrics dbMetrics,
146144
boolean batchedSeriesRetrieval, int batchedSeriesSize, boolean dumpIndex,
147-
File dumpIndexFile, int maxNonLeafPointsLoggedPerMin, String metricsStoreConfigFile,
148-
boolean longId) {
145+
File dumpIndexFile, int maxNonLeafPointsLoggedPerMin, String metricsStoreConfigFile) {
149146
this.nameIndex = Preconditions.checkNotNull(nameIndex);
150147
this.eventLogger = eventLogger;
151148
this.pointStore = Preconditions.checkNotNull(pointStore);
@@ -157,7 +154,6 @@ public TimeSeriesStoreImpl(MetricRegistry metricRegistry, MetricIndex nameIndex,
157154
this.dumpIndex = dumpIndex;
158155
this.dumpIndexFile = dumpIndexFile;
159156
this.nonLeafPointsLogQuota = new Quota(maxNonLeafPointsLoggedPerMin, 60);
160-
this.longId = longId;
161157

162158

163159
rejectedCounter = metricRegistry.counter(
@@ -362,11 +358,11 @@ public DataPointExportResults exportPoints(String dbName, String metricName) {
362358
}
363359

364360
@Override
365-
public DataPointExportResults exportPoints(String dbName, long metricId) {
361+
public DataPointExportResults exportPoints(String dbName, int metricId) {
366362
return exportPoints(dbName, null, metricId);
367363
}
368364

369-
private DataPointExportResults exportPoints(String dbName, String metricName, Long metricId) {
365+
private DataPointExportResults exportPoints(String dbName, String metricName, Integer metricId) {
370366
if (!RetentionPolicy.dbNameExists(dbName)) {
371367
throw new RuntimeException(String.format("Unknown dbName [%s]", dbName));
372368
}
@@ -645,13 +641,13 @@ public DeleteAPIResult deleteAPI( String name, boolean delete, Set<String> exclu
645641
}
646642

647643
@Override
648-
public Metric getMetric( long metricId )
644+
public Metric getMetric( int metricId )
649645
{
650646
return nameIndex.getMetric( metricId );
651647
}
652648

653649
@Override
654-
public String getMetricName( long metricId )
650+
public String getMetricName( int metricId )
655651
{
656652
return nameIndex.getMetricName( metricId );
657653
}
@@ -668,18 +664,11 @@ public void deleteAll()
668664
@Override
669665
public void scanMetrics( Consumer<Metric> m )
670666
{
671-
if(longId)
672-
{
673-
scanMetrics( 0, Long.MAX_VALUE, m );
674-
}
675-
else
676-
{
677-
scanMetrics( 0, Integer.MAX_VALUE, m );
678-
}
667+
scanMetrics( 0, Integer.MAX_VALUE, m );
679668
}
680669

681670
@Override
682-
public long scanMetrics( long start, long end, Consumer<Metric> m )
671+
public int scanMetrics( int start, int end, Consumer<Metric> m )
683672
{
684673
return nameIndex.scanNames( start, end, m );
685674
}

carbonj.service/src/main/java/com/demandware/carbonj/service/db/cfgTimeSeriesStorage.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
*/
77
package com.demandware.carbonj.service.db;
88

9+
import java.io.File;
10+
import java.util.concurrent.ScheduledExecutorService;
11+
import java.util.concurrent.TimeUnit;
12+
913
import com.codahale.metrics.MetricRegistry;
10-
import com.demandware.carbonj.service.db.index.cfgMetricIndex;
11-
import com.demandware.carbonj.service.db.model.DataPointStore;
12-
import com.demandware.carbonj.service.db.model.MetricIndex;
13-
import com.demandware.carbonj.service.db.points.cfgDataPoints;
14-
import com.demandware.carbonj.service.db.util.DatabaseMetrics;
1514
import com.demandware.carbonj.service.engine.cfgCentralThreadPools;
1615
import com.demandware.carbonj.service.events.EventsLogger;
1716
import com.demandware.carbonj.service.events.cfgCarbonjEventsLogger;
@@ -22,12 +21,15 @@
2221
import org.springframework.beans.factory.annotation.Value;
2322
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2423
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
2525
import org.springframework.context.annotation.DependsOn;
2626
import org.springframework.context.annotation.Import;
2727

28-
import java.io.File;
29-
import java.util.concurrent.ScheduledExecutorService;
30-
import java.util.concurrent.TimeUnit;
28+
import com.demandware.carbonj.service.db.index.cfgMetricIndex;
29+
import com.demandware.carbonj.service.db.model.DataPointStore;
30+
import com.demandware.carbonj.service.db.model.MetricIndex;
31+
import com.demandware.carbonj.service.db.points.cfgDataPoints;
32+
import com.demandware.carbonj.service.db.util.DatabaseMetrics;
3133

3234
@Import( { cfgMetricIndex.class, cfgDataPoints.class, cfgCentralThreadPools.class, cfgCarbonjEventsLogger.class } )
3335
@ConditionalOnProperty(name=cfgTimeSeriesStorage.DB_ENABLED_PROPERTY_KEY, havingValue="true", matchIfMissing=true)
@@ -37,9 +39,6 @@ public class cfgTimeSeriesStorage
3739

3840
public static final String DB_ENABLED_PROPERTY_KEY = "metrics.store.enabled";
3941

40-
@Value( "${metrics.store.longId:false}" )
41-
private boolean longId;
42-
4342
@Value( "${metrics.store.fetchSeriesThreads:20}" )
4443
private int nTaskThreads;
4544

@@ -86,8 +85,7 @@ TimeSeriesStore timeSeriesStore( MetricIndex nameIndex, DataPointStore pointStor
8685
TimeSeriesStoreImpl.newHeavyQueryTaskQueue( nHeavyQueryThreads, heavyQueryBlockingQueueSize ),
8786
TimeSeriesStoreImpl.newSerialTaskQueue( serialQueueSize ), pointStore,
8887
dbMetrics, batchedSeriesRetrieval,
89-
batchedSeriesSize, dumpIndex, new File( dumpIndexFile ), maxNonLeafPointsLoggedPerMin, metricStoreConfigFile,
90-
longId);
88+
batchedSeriesSize, dumpIndex, new File( dumpIndexFile ), maxNonLeafPointsLoggedPerMin, metricStoreConfigFile);
9189

9290
s.scheduleWithFixedDelay(timeSeriesStore::reload, 60, 60, TimeUnit.SECONDS );
9391
s.scheduleWithFixedDelay(timeSeriesStore::refreshStats, 60, 10, TimeUnit.SECONDS );

carbonj.service/src/main/java/com/demandware/carbonj/service/db/index/IdRecord.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
import com.google.common.base.Preconditions;
1010

1111
class IdRecord
12-
implements Record<Long>
12+
implements Record<Integer>
1313
{
14-
private Long key;
14+
private Integer key;
1515

1616
private String metricName;
1717

18-
public IdRecord( Long key, String metricName)
18+
public IdRecord( Integer key, String metricName)
1919
{
2020
this.key = Preconditions.checkNotNull(key);
2121
this.metricName = Preconditions.checkNotNull(metricName);
2222
}
2323

24-
public Long key()
24+
public Integer key()
2525
{
2626
return key;
2727
}

carbonj.service/src/main/java/com/demandware/carbonj/service/db/index/IdRecordSerializer.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,47 @@
66
*/
77
package com.demandware.carbonj.service.db.index;
88

9-
import com.google.common.io.ByteArrayDataInput;
10-
import com.google.common.io.ByteArrayDataOutput;
11-
import com.google.common.io.ByteStreams;
129
import com.google.common.primitives.Ints;
13-
import com.google.common.primitives.Longs;
10+
11+
import static java.nio.charset.StandardCharsets.UTF_8;
1412

1513
class IdRecordSerializer
16-
implements RecordSerializer<Long, IdRecord>
14+
implements RecordSerializer<Integer, IdRecord>
1715
{
18-
private boolean longId;
19-
20-
public IdRecordSerializer(boolean longId)
16+
public IdRecordSerializer()
2117
{
22-
this.longId = longId;
2318
}
2419

2520
@Override
26-
public Long key( byte[] keyBytes )
21+
public Integer key( byte[] keyBytes )
2722
{
28-
return longId ? Longs.fromByteArray( keyBytes ) : Integer.valueOf(Ints.fromByteArray(keyBytes)).longValue();
23+
return Ints.fromByteArray( keyBytes );
2924
}
3025

3126
@Override
3227
public IdRecord toIndexEntry( byte[] keyBytes, byte[] valueBytes)
3328
{
34-
Long key = key(keyBytes);
29+
Integer key = key(keyBytes);
3530
return toIndexEntry( key, valueBytes);
3631
}
3732

3833
@Override
39-
public IdRecord toIndexEntry( Long key, byte[] valueBytes)
34+
public IdRecord toIndexEntry( Integer key, byte[] valueBytes)
4035
{
41-
ByteArrayDataInput in = ByteStreams.newDataInput( valueBytes );
42-
if(longId)
43-
{
44-
// a byte for versioning
45-
byte entryType = in.readByte();
46-
}
47-
return new IdRecord( key, in.readUTF() );
36+
String value = new String(valueBytes, UTF_8);
37+
return new IdRecord( key, value );
4838
}
4939

5040
@Override
51-
public byte[] keyBytes(Long key)
41+
public byte[] keyBytes(Integer key)
5242
{
53-
return longId ? Longs.toByteArray(key) : Ints.toByteArray(key.intValue());
43+
return Ints.toByteArray(key);
5444
}
5545

5646
@Override
5747
public byte[] valueBytes(IdRecord e)
5848
{
59-
ByteArrayDataOutput out = ByteStreams.newDataOutput();
60-
if(longId)
61-
{
62-
// leaving a byte for versioning
63-
out.writeByte(0);
64-
}
65-
out.writeUTF(e.metricName());
66-
return out.toByteArray();
49+
return e.metricName().getBytes( UTF_8 );
6750
}
6851

6952
}

carbonj.service/src/main/java/com/demandware/carbonj/service/db/index/IndexStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ public interface IndexStore<K, R extends Record<K>>
2929

3030
K maxKey();
3131

32-
long scan( K startKey, K endKey, Consumer<R> c );
32+
int scan( K startKey, K endKey, Consumer<R> c );
3333
}

0 commit comments

Comments
 (0)