Skip to content

Commit

Permalink
Releasing New Storage Engine (#68)
Browse files Browse the repository at this point in the history
* Adding file channel close as a temporary solution to max open files limit '#31'

* New storage engine implementation #31 (#66)

Cleaning up archival moving sql package

time series buckets

Fixing bugs with refactor

and diskstorage engine

Validating and fixing unit tests

windows)

adding unit tests for persistent measurement

Adding concurrency fixes #31

Fixing recovery bug

Fixing broken recovery system due to missing offsets, fixing unit tests
for recovery, adding parallel recovery for measurements

Improving test converage

Fixing minor code issues

fixing potential concurrency issue

* Adding basic GRPC code for writes with disruptor (#67)

Fixing rpc build issue

Fixing pom issue
  • Loading branch information
ambud committed Aug 23, 2017
1 parent 78a21ce commit 13be34c
Show file tree
Hide file tree
Showing 155 changed files with 3,753 additions and 30,832 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import com.srotya.sidewinder.core.storage.ArchiveException;
import com.srotya.sidewinder.core.storage.Archiver;
import com.srotya.sidewinder.core.storage.DataPoint;
import com.srotya.sidewinder.core.storage.Reader;
import com.srotya.sidewinder.core.storage.TimeSeriesBucket;
import com.srotya.sidewinder.core.storage.compression.Reader;
import com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter;
import com.srotya.sidewinder.core.storage.mem.archival.TimeSeriesArchivalObject;

Expand Down Expand Up @@ -60,7 +60,8 @@ public void testHDFSArchive() throws IOException, ArchiveException {
conf.put(HDFSArchiver.HDFS_ARCHIVE_DIRECTORY, "target/test-hdfs-" + System.currentTimeMillis());
archiver.init(conf);
long ts = System.currentTimeMillis();
TimeSeriesBucket bucket = new TimeSeriesBucket("seriesId", ByzantineWriter.class.getName(), ts, false, new HashMap<>());
//TODO fix unit tests for HDFS Archiver
TimeSeriesBucket bucket = null;
for (int i = 0; i < 1000; i++) {
bucket.addDataPoint(ts + i * 1000, i);
}
Expand Down
53 changes: 9 additions & 44 deletions cluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,30 @@
<linea.version>0.0.15</linea.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.facebook.jcommon</groupId>
<artifactId>util</artifactId>
<version>0.1.29</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>com.srotya.sidewinder</groupId>
<artifactId>sidewinder-core</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.srotya.sidewinder</groupId>
<artifactId>sidewinder-rpc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-all</artifactId>
<version>1.0.5</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-resolver</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
Expand All @@ -80,17 +48,14 @@
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Arrays;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.srotya.sidewinder.cluster.connectors.ClusterConnector;
import com.srotya.sidewinder.core.storage.DataPoint;
Expand All @@ -30,7 +32,7 @@
public class ClusterResourceMonitor {

private static final String DB = "_internal";
// private static Logger logger = Logger.getLogger(ClusterResourceMonitor.class.getName());
private static Logger logger = Logger.getLogger(ClusterResourceMonitor.class.getName());
private static final ClusterResourceMonitor INSTANCE = new ClusterResourceMonitor();
private StorageEngine storageEngine;
private ClusterConnector connector;
Expand Down Expand Up @@ -67,8 +69,7 @@ private void clusterMonitor() {
dp.setTags(Arrays.asList("controller"));
storageEngine.writeDataPoint(dp);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.log(Level.SEVERE, "Failed to monitor cluster", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import com.codahale.metrics.MetricRegistry;
import com.srotya.sidewinder.cluster.routing.Node;
import com.srotya.sidewinder.cluster.routing.RoutingEngine;
import com.srotya.sidewinder.core.ingress.http.HTTPDataPointDecoder;
import com.srotya.sidewinder.core.rpc.Point;
import com.srotya.sidewinder.core.storage.RejectException;
import com.srotya.sidewinder.core.utils.HTTPDataPointDecoder;
import com.srotya.sidewinder.core.utils.MiscUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.srotya.sidewinder.core.rpc.RawTimeSeriesBucket;
import com.srotya.sidewinder.core.rpc.RawTimeSeriesBucket.Builder;
import com.srotya.sidewinder.core.storage.StorageEngine;
import com.srotya.sidewinder.core.storage.TimeSeries;
import com.srotya.sidewinder.core.storage.TimeSeriesBucket;
import com.srotya.sidewinder.core.storage.mem.TimeSeries;

/**
* Routing Engine provides the abstraction to stitch together the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/**
* Copyright 2017 Ambud Sharma
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.srotya.sidewinder.cluster.rpc;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;

import com.google.protobuf.ByteString;
import com.google.protobuf.ProtocolStringList;
import com.srotya.sidewinder.cluster.rpc.ListTimeseriesOffsetResponse.OffsetEntry;
import com.srotya.sidewinder.cluster.rpc.ListTimeseriesOffsetResponse.OffsetEntry.Bucket;
import com.srotya.sidewinder.cluster.rpc.ReplicationServiceGrpc.ReplicationServiceImplBase;
import com.srotya.sidewinder.core.storage.Measurement;
import com.srotya.sidewinder.core.storage.StorageEngine;
import com.srotya.sidewinder.core.storage.TimeSeries;
import com.srotya.sidewinder.core.storage.TimeSeriesBucket;

import io.grpc.stub.StreamObserver;

/**
* @author ambud
*/
public class ReplicationServiceImpl extends ReplicationServiceImplBase {

private StorageEngine engine;

public ReplicationServiceImpl(StorageEngine engine) {
this.engine = engine;
}

@Override
public void listBatchTimeseriesOffsetList(ListTimeseriesOffsetRequest request,
StreamObserver<ListTimeseriesOffsetResponse> responseObserver) {
String dbName = request.getDbName();
String measurementName = request.getMeasurementName();
try {
Measurement measurement = engine.getOrCreateMeasurement(dbName, measurementName);

ListTimeseriesOffsetResponse.Builder builder = ListTimeseriesOffsetResponse.newBuilder();
for (TimeSeries timeSeries : measurement.getTimeSeries()) {
OffsetEntry.Builder offsetBuilder = OffsetEntry.newBuilder();

String seriesId = timeSeries.getSeriesId();
String[] keys = seriesId.split(Measurement.FIELD_TAG_SEPARATOR);
String valueFieldName = keys[0];

List<String> tags = Measurement.decodeStringToTags(measurement.getTagIndex(), keys[1]);
offsetBuilder.setValueFieldName(valueFieldName);
offsetBuilder.addAllTags(tags);

SortedMap<String, List<TimeSeriesBucket>> bucketRawMap = timeSeries.getBucketRawMap();
for (Entry<String, List<TimeSeriesBucket>> entry : bucketRawMap.entrySet()) {
for (int i = 0; i < entry.getValue().size(); i++) {
TimeSeriesBucket timeSeriesBucket = entry.getValue().get(i);
OffsetEntry.Bucket.Builder bucket = Bucket.newBuilder();
bucket.setIndex(i);
bucket.setOffset(timeSeriesBucket.getWriter().currentOffset());
bucket.setBucketTs(entry.getKey());
offsetBuilder.addBuckets(bucket.build());
}
}
builder.addEntries(offsetBuilder.build());
}
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} catch (Exception e) {
responseObserver.onError(e);
}
}

@Override
public void batchFetchTimeseriesDataAtOffset(BatchRawTimeSeriesOffsetRequest request,
StreamObserver<BatchRawTimeSeriesOffsetResponse> responseObserver) {
BatchRawTimeSeriesOffsetResponse.Builder rawBuilder = BatchRawTimeSeriesOffsetResponse.newBuilder();
List<RawTimeSeriesOffsetRequest> requestsList = request.getRequestsList();
for (RawTimeSeriesOffsetRequest rawRequest : requestsList) {
RawTimeSeriesOffsetResponse.Builder builder = RawTimeSeriesOffsetResponse.newBuilder();

String dbName = rawRequest.getDbName();
String measurementName = rawRequest.getMeasurementName();
String valueFieldName = rawRequest.getValueFieldName();
ProtocolStringList tags = rawRequest.getTagsList();
long blockTimestamp = rawRequest.getBlockTimestamp();
int index = rawRequest.getIndex();
int offset = rawRequest.getOffset();
int bucketSize = rawRequest.getBucketSize();
try {
TimeSeries timeSeries = engine.getTimeSeries(dbName, measurementName, valueFieldName,
new ArrayList<>(tags));
String timeBucket = TimeSeries.getTimeBucket(TimeUnit.MILLISECONDS, blockTimestamp, bucketSize);
SortedMap<String, List<TimeSeriesBucket>> bucketRawMap = timeSeries.getBucketRawMap();
List<TimeSeriesBucket> list = bucketRawMap.get(timeBucket);
TimeSeriesBucket timeSeriesBucket = list.get(index);
builder.setBlockTimestamp(blockTimestamp);
builder.setDbName(dbName);
builder.setMeasurementName(measurementName);
builder.setBucketSize(bucketSize);
builder.setMessageId(request.getMessageId());
builder.setFp(timeSeries.isFp());
builder.setValueFieldName(valueFieldName);
builder.addAllTags(tags);
builder.setIndex(index);

builder.setCount(timeSeriesBucket.getCount());
ByteBuffer buf = timeSeriesBucket.getWriter().getRawBytes();
buf.position(offset);
builder.setData(ByteString.copyFrom(buf));
rawBuilder.addResponses(builder.build());
} catch (Exception e) {
e.printStackTrace();
responseObserver.onError(e);
}
}
responseObserver.onNext(rawBuilder.build());
responseObserver.onCompleted();
}

@Override
public void fetchTimeseriesDataAtOffset(RawTimeSeriesOffsetRequest request,
StreamObserver<RawTimeSeriesOffsetResponse> responseObserver) {
RawTimeSeriesOffsetResponse.Builder builder = RawTimeSeriesOffsetResponse.newBuilder();

String dbName = request.getDbName();
String measurementName = request.getMeasurementName();
String valueFieldName = request.getValueFieldName();
ProtocolStringList tags = request.getTagsList();
long blockTimestamp = request.getBlockTimestamp();
int index = request.getIndex();
int offset = request.getOffset();
int bucketSize = request.getBucketSize();
try {
TimeSeries timeSeries = engine.getTimeSeries(dbName, measurementName, valueFieldName,
new ArrayList<>(tags));
String timeBucket = TimeSeries.getTimeBucket(TimeUnit.MILLISECONDS, blockTimestamp, bucketSize);
SortedMap<String, List<TimeSeriesBucket>> bucketRawMap = timeSeries.getBucketRawMap();
List<TimeSeriesBucket> list = bucketRawMap.get(timeBucket);
TimeSeriesBucket timeSeriesBucket = list.get(index);

builder.setBlockTimestamp(blockTimestamp);
builder.setDbName(dbName);
builder.setMeasurementName(measurementName);
builder.setBucketSize(bucketSize);
builder.setMessageId(request.getMessageId());
builder.setFp(timeSeries.isFp());
builder.setValueFieldName(valueFieldName);
builder.addAllTags(tags);
builder.setIndex(index);
builder.setCount(timeSeriesBucket.getCount());
ByteBuffer buf = timeSeriesBucket.getWriter().getRawBytes();
buf.position(offset);
builder.setData(ByteString.copyFrom(buf));

responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} catch (Exception e) {
e.printStackTrace();
responseObserver.onError(e);
}
}

}
Loading

0 comments on commit 13be34c

Please sign in to comment.