Skip to content

Commit 1882677

Browse files
authored
Reformatt code using google java style formatter (#861)
Add the formatter and updated README
1 parent d1d28aa commit 1882677

File tree

45 files changed

+567
-540
lines changed

Some content is hidden

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

45 files changed

+567
-540
lines changed

dbsync/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Compiling the code from source requires `Java 8`, running the tools requires
88
`Java 8` or higher. To check Java version run the command`java -version` or
99
refer to Java vendor documentation.
1010

11+
## Contributing
12+
13+
Before submitting any code changes, please run the formatter
14+
15+
java -jar dbsync/google-java-format-1.7-all-deps.jar -i $(git ls-files|grep \.java$)
16+
1117
## Gcysnc
1218

1319
This tool is in preview mode, it's being actively developed.

dbsync/client/src/main/java/com/google/edwmigration/dbsync/client/GcsClientMain.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,45 @@
22

33
import com.google.edwmigration.dbsync.common.DefaultArguments;
44
import java.net.URI;
5-
import java.util.logging.Logger;
65
import java.util.logging.Level;
6+
import java.util.logging.Logger;
77
import joptsimple.OptionSpec;
88

99
public class GcsClientMain {
1010

1111
private static class Arguments extends DefaultArguments {
1212

1313
private final OptionSpec<String> projectOptionSpec =
14-
parser.accepts("project", "Specifies the destination project")
14+
parser
15+
.accepts("project", "Specifies the destination project")
1516
.withRequiredArg()
1617
.ofType(String.class)
1718
.required();
1819

1920
private final OptionSpec<String> locationOptionSpec =
20-
parser.accepts("location", "Specifies the gcp location")
21+
parser
22+
.accepts("location", "Specifies the gcp location")
2123
.withRequiredArg()
2224
.ofType(String.class)
2325
.required();
2426

2527
private final OptionSpec<String> targetOptionSpec =
26-
parser.accepts("target_file", "Specifies the target file")
28+
parser
29+
.accepts("target_file", "Specifies the target file")
2730
.withRequiredArg()
2831
.ofType(String.class)
2932
.required();
3033

3134
private final OptionSpec<String> sourceOptionSpec =
32-
parser.accepts("source_file", "Specifies the source file")
35+
parser
36+
.accepts("source_file", "Specifies the source file")
3337
.withRequiredArg()
3438
.ofType(String.class)
3539
.required();
3640

3741
private final OptionSpec<String> stagingBucketOptionSpec =
38-
parser.accepts("staging_bucket", "Specifies the staging bucket")
42+
parser
43+
.accepts("staging_bucket", "Specifies the staging bucket")
3944
.withRequiredArg()
4045
.ofType(String.class)
4146
.required();
@@ -74,8 +79,7 @@ public static void main(String[] args) {
7479
arguments.getLocation(),
7580
new URI(arguments.getSourceUri()),
7681
new URI(arguments.getStagingBucket() + "/"),
77-
new URI(arguments.getTargetUri())
78-
);
82+
new URI(arguments.getTargetUri()));
7983
} catch (Exception e) {
8084
Logger.getLogger("rsync").log(Level.INFO, e.getMessage(), e);
8185
}

dbsync/client/src/main/java/com/google/edwmigration/dbsync/client/RsyncClient.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.google.edwmigration.dbsync.client;
22

3-
4-
import com.google.edwmigration.dbsync.server.CloudRunServerAPI;
3+
import com.google.common.io.ByteSink;
4+
import com.google.common.io.ByteSource;
55
import com.google.edwmigration.dbsync.common.InstructionGenerator;
66
import com.google.edwmigration.dbsync.common.storage.LocalStorage;
77
import com.google.edwmigration.dbsync.proto.Checksum;
8+
import com.google.edwmigration.dbsync.server.CloudRunServerAPI;
89
import com.google.edwmigration.dbsync.server.GCSTarget;
910
import com.google.edwmigration.dbsync.server.RsyncTarget;
10-
import com.google.common.io.ByteSink;
11-
import com.google.common.io.ByteSource;
1211
import java.io.IOException;
1312
import java.io.InputStream;
1413
import java.io.OutputStream;
@@ -27,7 +26,8 @@ public class RsyncClient {
2726
// GcsClientMain calls this.
2827
// Validation calls this.
2928
// TODO support multiple files ?
30-
public void putRsync(String projectId, String location, URI sourceUri, URI stagingBucket, URI targetUri)
29+
public void putRsync(
30+
String projectId, String location, URI sourceUri, URI stagingBucket, URI targetUri)
3131
throws IOException, ExecutionException, InterruptedException {
3232
ByteSource byteSource;
3333
switch (sourceUri.getScheme()) {
@@ -47,7 +47,7 @@ public void putRsync(String projectId, String location, URI sourceUri, URI stagi
4747
if (byteSource.size() < MIN_SIZE_TO_RSYNC) {
4848
throw new IllegalStateException("dont handle small files");
4949
} else {
50-
//TODO move this out of the put rsync and into a initialization function to be called once
50+
// TODO move this out of the put rsync and into a initialization function to be called once
5151
server.deployRsyncJobs();
5252
putRsync(byteSource, server, new GCSTarget(projectId, targetUri, stagingBucket));
5353
}
@@ -73,18 +73,21 @@ private void putRsync(ByteSource source, CloudRunServerAPI server, RsyncTarget t
7373
InstructionGenerator generator = new InstructionGenerator(CHECKSUM_BLOCK_SIZE);
7474
ByteSink instructionSink = target.getInstructionsByteSink();
7575
try (OutputStream instructionStream = instructionSink.openBufferedStream()) {
76-
generator.generate(instruction -> {
77-
try {
78-
instruction.writeDelimitedTo(instructionStream);
79-
} catch (IOException e) {
80-
throw new RuntimeException("Failed to write instructions", e);
81-
}
82-
}, source, targetChecksums);
76+
generator.generate(
77+
instruction -> {
78+
try {
79+
instruction.writeDelimitedTo(instructionStream);
80+
} catch (IOException e) {
81+
throw new RuntimeException("Failed to write instructions", e);
82+
}
83+
},
84+
source,
85+
targetChecksums);
8386
}
8487

8588
// Reconstruct on GCS
8689
server.reconstruct();
8790

88-
//TODO delete the jobs from cloudrun
91+
// TODO delete the jobs from cloudrun
8992
}
9093
}

dbsync/common/src/jmh/java/com/google/edwmigration/dbsync/jmh/RollingChecksumBenchmark.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import org.openjdk.jmh.infra.Blackhole;
1717

1818
@State(Scope.Benchmark)
19-
@Fork(value=2)
20-
@Warmup(iterations=2, time=RollingChecksumBenchmark.MS, timeUnit = TimeUnit.MILLISECONDS )
21-
@Measurement(iterations=4, time=RollingChecksumBenchmark.MS, timeUnit = TimeUnit.MILLISECONDS)
19+
@Fork(value = 2)
20+
@Warmup(iterations = 2, time = RollingChecksumBenchmark.MS, timeUnit = TimeUnit.MILLISECONDS)
21+
@Measurement(iterations = 4, time = RollingChecksumBenchmark.MS, timeUnit = TimeUnit.MILLISECONDS)
2222
public class RollingChecksumBenchmark {
2323
public static final int MS = 1000;
2424
private static final int N = 1024;
@@ -35,14 +35,13 @@ public void setUp() throws Exception {
3535
}
3636

3737
@Benchmark
38-
public void testResetBytes(Blackhole bh) throws Exception{
39-
for (int i = 0; i < N; i++)
40-
impl.reset(bytes, 0);
38+
public void testResetBytes(Blackhole bh) throws Exception {
39+
for (int i = 0; i < N; i++) impl.reset(bytes, 0);
4140
bh.consume(impl);
4241
}
4342

4443
@Benchmark
45-
public void testResetStream(Blackhole bh) throws Exception{
44+
public void testResetStream(Blackhole bh) throws Exception {
4645
for (int i = 0; i < N; i++) {
4746
stream.reset();
4847
impl.reset(stream);

dbsync/common/src/main/java/com/google/edwmigration/dbsync/common/AlgorithmConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
public interface AlgorithmConstants {
44
public static final int MAX_LITERAL_LENGTH = 4096;
5-
65
}

dbsync/common/src/main/java/com/google/edwmigration/dbsync/common/ChecksumGenerator.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.google.edwmigration.dbsync.common;
22

3-
import com.google.edwmigration.dbsync.proto.Checksum;
43
import com.google.common.base.Optional;
54
import com.google.common.hash.HashCode;
65
import com.google.common.io.ByteSource;
76
import com.google.common.primitives.Ints;
7+
import com.google.edwmigration.dbsync.proto.Checksum;
88
import com.google.protobuf.ByteString;
99
import java.io.IOException;
1010
import java.io.InputStream;
@@ -16,6 +16,7 @@ public class ChecksumGenerator {
1616

1717
@SuppressWarnings("unused")
1818
private static final Logger logger = LoggerFactory.getLogger(ChecksumGenerator.class);
19+
1920
private static final boolean DEBUG = false;
2021

2122
private final @NonNegative int blockSize;
@@ -48,31 +49,40 @@ public void generate(ChecksumConsumer<IOException> out, ByteSource in) throws IO
4849
// Yes, this masks the instance variable.
4950
int blockSize = rollingChecksum.getBlockSize();
5051
if (DEBUG) {
51-
logger.info("Generating checksums for [{} .. +{}] in {} bytes", offset, blockSize,
52-
dataSize);
52+
logger.info(
53+
"Generating checksums for [{} .. +{}] in {} bytes", offset, blockSize, dataSize);
5354
}
5455

55-
// If someone changes the size of the ByteSource underneath us, this might throw EOFException.
56+
// If someone changes the size of the ByteSource underneath us, this might throw
57+
// EOFException.
5658
rollingChecksum.reset(i);
5759
int weakHashCode = rollingChecksum.getWeakHashCode();
5860
HashCode strongHashCode = rollingChecksum.getStrongHashCode();
5961

6062
if (DEBUG) {
61-
HashCode _strongHashCode = RollingChecksumImpl.STRONG_HASH_FUNCTION.hashBytes(dataArray,
62-
Ints.checkedCast(offset), blockSize);
63+
HashCode _strongHashCode =
64+
RollingChecksumImpl.STRONG_HASH_FUNCTION.hashBytes(
65+
dataArray, Ints.checkedCast(offset), blockSize);
6366
if (!strongHashCode.equals(_strongHashCode)) {
6467
throw new IllegalStateException(
65-
"Bad hash code at " + offset + "..+" + blockSize + ": " + strongHashCode + " != "
68+
"Bad hash code at "
69+
+ offset
70+
+ "..+"
71+
+ blockSize
72+
+ ": "
73+
+ strongHashCode
74+
+ " != "
6675
+ _strongHashCode);
6776
}
6877
}
6978

70-
Checksum c = Checksum.newBuilder()
71-
.setBlockOffset(offset)
72-
.setBlockLength(blockSize)
73-
.setWeakChecksum(weakHashCode)
74-
.setStrongChecksum(ByteString.copyFrom(strongHashCode.asBytes()))
75-
.build();
79+
Checksum c =
80+
Checksum.newBuilder()
81+
.setBlockOffset(offset)
82+
.setBlockLength(blockSize)
83+
.setWeakChecksum(weakHashCode)
84+
.setStrongChecksum(ByteString.copyFrom(strongHashCode.asBytes()))
85+
.build();
7686
out.accept(c);
7787
}
7888
}

dbsync/common/src/main/java/com/google/edwmigration/dbsync/common/DefaultArguments.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package com.google.edwmigration.dbsync.common;
1818

19-
import com.google.common.base.Joiner;
2019
import com.google.common.base.MoreObjects;
2120
import com.google.common.base.Throwables;
2221
import java.io.IOException;
@@ -26,8 +25,6 @@
2625
import joptsimple.OptionParser;
2726
import joptsimple.OptionSet;
2827
import joptsimple.OptionSpec;
29-
import joptsimple.ValueConversionException;
30-
import joptsimple.ValueConverter;
3128
import org.anarres.jdiagnostics.ProductMetadata;
3229
import org.slf4j.Logger;
3330
import org.slf4j.LoggerFactory;

dbsync/common/src/main/java/com/google/edwmigration/dbsync/common/DefaultHashStrategies.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ public class DefaultHashStrategies {
1111
public static final Int64 INSTANCE64 = new Int64();
1212
public static final ByteArray BYTE_ARRAY = new ByteArray();
1313

14-
/**
15-
* Based on Thomas Wang's code from https://gist.github.com/badboy/6267743
16-
*/
14+
/** Based on Thomas Wang's code from https://gist.github.com/badboy/6267743 */
1715
@SuppressWarnings("UnnecessaryParentheses")
1816
public static int hash_mix_64_to_32(long key) {
1917
key = (~key) + (key << 18); // key = (key << 18) - key - 1;
@@ -25,9 +23,7 @@ public static int hash_mix_64_to_32(long key) {
2523
return (int) key;
2624
}
2725

28-
/**
29-
* Based on http://www.burtleburtle.net/bob/hash/integer.html .
30-
*/
26+
/** Based on http://www.burtleburtle.net/bob/hash/integer.html . */
3127
public static int hash_mix_full(int a) {
3228
a = (a + 0x7ed55d16) + (a << 12);
3329
a = (a ^ 0xc761c23c) ^ (a >> 19);
@@ -42,9 +38,7 @@ public static int hash_mix_full(long a) {
4238
return hash_mix_full(Long.hashCode(a));
4339
}
4440

45-
/**
46-
* Based on http://www.burtleburtle.net/bob/hash/integer.html .
47-
*/
41+
/** Based on http://www.burtleburtle.net/bob/hash/integer.html . */
4842
public static int hash_mix_low(int a) {
4943
a += ~(a << 15);
5044
a ^= (a >> 10);

dbsync/common/src/main/java/com/google/edwmigration/dbsync/common/InstructionGenerator.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package com.google.edwmigration.dbsync.common;
22

3+
import com.google.common.io.ByteSource;
34
import com.google.edwmigration.dbsync.proto.BlockLocation;
45
import com.google.edwmigration.dbsync.proto.Checksum;
56
import com.google.edwmigration.dbsync.proto.Instruction;
6-
import com.google.common.hash.HashCode;
7-
import com.google.common.io.ByteSource;
87
import com.google.protobuf.ByteString;
98
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
109
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
1110
import java.io.IOException;
1211
import java.io.InputStream;
13-
import java.net.URI;
14-
import java.net.URISyntaxException;
1512
import java.util.ArrayList;
1613
import java.util.Arrays;
1714
import java.util.Collection;
1815
import java.util.List;
19-
import java.util.function.Consumer;
2016
import org.checkerframework.checker.index.qual.NonNegative;
2117
import org.slf4j.Logger;
2218
import org.slf4j.LoggerFactory;
@@ -25,6 +21,7 @@ public class InstructionGenerator {
2521

2622
@SuppressWarnings("unused")
2723
private static final Logger logger = LoggerFactory.getLogger(InstructionGenerator.class);
24+
2825
private static final boolean DEBUG = false;
2926

3027
private final int blockSize;
@@ -39,8 +36,11 @@ private static Instruction newLiteralInstruction(byte[] literalBuffer, int liter
3936
.build();
4037
}
4138

42-
public void generate(InstructionConsumer<? extends IOException> out, ByteSource in,
43-
List<? extends Checksum> checksums) throws IOException {
39+
public void generate(
40+
InstructionConsumer<? extends IOException> out,
41+
ByteSource in,
42+
List<? extends Checksum> checksums)
43+
throws IOException {
4444
Int2ObjectMap<Collection<Checksum>> checksumMap = new Int2ObjectOpenHashMap<>(checksums.size());
4545
for (Checksum c : checksums) {
4646
checksumMap.computeIfAbsent(c.getWeakChecksum(), k -> new ArrayList<>()).add(c);
@@ -53,8 +53,8 @@ public void generate(InstructionConsumer<? extends IOException> out, ByteSource
5353
int blockSize = checksums.isEmpty() ? this.blockSize : checksums.get(0).getBlockLength();
5454

5555
@NonNegative int rollingBlockLength;
56-
final byte[] literalBuffer = new byte[Math.min(blockSize,
57-
AlgorithmConstants.MAX_LITERAL_LENGTH)];
56+
final byte[] literalBuffer =
57+
new byte[Math.min(blockSize, AlgorithmConstants.MAX_LITERAL_LENGTH)];
5858
@NonNegative int literalBufferLength = 0;
5959

6060
// int lastBlockSize = checksums.get(checksums.size() - 1).getBlockLength();
@@ -85,11 +85,13 @@ public void generate(InstructionConsumer<? extends IOException> out, ByteSource
8585
out.accept(newLiteralInstruction(literalBuffer, literalBufferLength));
8686
literalBufferLength = 0;
8787
}
88-
Instruction insn = Instruction.newBuilder()
89-
.setBlockLocation(BlockLocation.newBuilder()
90-
.setBlockOffset(c.getBlockOffset())
91-
.setBlockLength(c.getBlockLength()))
92-
.build();
88+
Instruction insn =
89+
Instruction.newBuilder()
90+
.setBlockLocation(
91+
BlockLocation.newBuilder()
92+
.setBlockOffset(c.getBlockOffset())
93+
.setBlockLength(c.getBlockLength()))
94+
.build();
9395
out.accept(insn);
9496
continue STREAM;
9597
}
@@ -132,10 +134,7 @@ public void generate(InstructionConsumer<? extends IOException> out, ByteSource
132134

133135
public interface InstructionConsumer<X extends Exception> {
134136

135-
/**
136-
* Accepts an instruction from the generator
137-
*/
137+
/** Accepts an instruction from the generator */
138138
void accept(Instruction instruction) throws X;
139139
}
140-
141140
}

0 commit comments

Comments
 (0)