Skip to content

Commit 8f6916a

Browse files
authored
Merge pull request #68 from urbanairship/fixmodbug
Fix mod bug since 1.4.0
2 parents bb48abc + 25f5930 commit 8f6916a

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

RELEASE_NOTES.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2.0.0
2+
=====
3+
Non compatible update with existing data cubes. The DataCube constructor in
4+
previous versions with the useAddressPrefixByteHash parameter set to true is
5+
compatible with PREFIX_MODE.NO_ADDRESS_PREFIX, but is not compatible with the
6+
new mode PREFIX_MODE.MOD_ADDRESS_PREFIX because there was a bug since 1.4.0
7+
that didn't implement this feature correctly.
8+
19
1.5.0
210
=====
311
Prevent getId calls from creating a new identifier
@@ -6,7 +14,6 @@ Optimize id creation.
614

715
1.4.0
816
=====
9-
1017
Add functionality to optionally add a hash in front of row keys, which permits
1118
users to ignore dimension order when considering performance.
1219

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.urbanairship</groupId>
55
<artifactId>datacube</artifactId>
6-
<version>1.5.1-SNAPSHOT</version>
6+
<version>2.0.0-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<name>datacube</name>

src/main/java/com/urbanairship/datacube/Address.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,25 @@ private Optional<byte[]> toKey(IdService idService, boolean readOnly) throws IOE
146146
for (byte[] keyElement : keyElemsInOrder) {
147147
totalKeySize += keyElement.length;
148148
}
149-
ByteBuffer bb = ByteBuffer.allocate(totalKeySize);
150-
149+
ByteBuffer bb;
150+
// Add a place holder for the hash byte if it's required
151+
if (this.cube.useAddressPrefixByteHash()) {
152+
bb = ByteBuffer.allocate(totalKeySize + 1);
153+
bb.put((byte) 0x01);
154+
} else {
155+
bb = ByteBuffer.allocate(totalKeySize);
156+
}
151157

152158
for (byte[] keyElement : keyElemsInOrder) {
153159
bb.put(keyElement);
154160
}
155161

162+
// Update the byte prefix placeholder of the hash of the key contents if required.
163+
if (this.cube.useAddressPrefixByteHash()) {
164+
byte hashByte = Util.hashByteArray(bb.array(), 1, totalKeySize + 1);
165+
bb.put(0, hashByte);
166+
}
167+
156168
if (bb.remaining() != 0) {
157169
throw new AssertionError("Key length calculation was somehow wrong, " +
158170
bb.remaining() + " bytes remaining");

src/main/java/com/urbanairship/datacube/DataCube.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
public class DataCube<T extends Op> {
3030
private static final Logger log = LoggerFactory.getLogger(DataCube.class);
3131

32+
public enum PREFIX_MODE { NO_ADDRESS_PREFIX, MOD_ADDRESS_PREFIX}
33+
3234
private final List<Dimension<?>> dims;
3335
private final List<Rollup> rollups;
3436
private final Multimap<Dimension<?>,BucketType> bucketsOfInterest;
@@ -42,25 +44,30 @@ public class DataCube<T extends Op> {
4244
* @param rollups see {@link Rollup}
4345
*/
4446
public DataCube(List<Dimension<?>> dims, List<Rollup> rollups) {
45-
this(dims, rollups, false);
47+
this(dims, rollups, PREFIX_MODE.NO_ADDRESS_PREFIX);
4648
}
4749

4850
/**
4951
*
5052
* @param dims see {@link Dimension}
5153
* @param rollups see {@link Rollup}
52-
* @param useAddressPrefixByteHash Prefix the keys by a hash byte (calculated by hashing each element
54+
* @param prefixMode use MOD_ADDRESS_PREFIX to prefix the keys by a hash byte (calculated by hashing each element
5355
* in the key). This is only a storage artifact to benefit systems
5456
* like HBase, where monotonically increasing row keys can result in
5557
* hot spots.
56-
* Warning: Do NOT enable or disable this feature for an existing cube or
57-
* the keys will not map properly.
58+
* Warning: Do NOT switch modes for an existing cube or the keys will
59+
* not map properly. Also, data from versions of datacube before 2.0.0,
60+
* with this feature enabled, is not compatible with 2.0.0+.
5861
*/
59-
public DataCube(List<Dimension<?>> dims, List<Rollup> rollups, boolean useAddressPrefixByteHash) {
62+
public DataCube(List<Dimension<?>> dims, List<Rollup> rollups, PREFIX_MODE prefixMode) {
6063
this.dims = dims;
6164
this.rollups = rollups;
6265
this.validAddressSet = Sets.newHashSet();
63-
this.useAddressPrefixByteHash = useAddressPrefixByteHash;
66+
if (PREFIX_MODE.MOD_ADDRESS_PREFIX == prefixMode) {
67+
this.useAddressPrefixByteHash = true;
68+
} else {
69+
this.useAddressPrefixByteHash = false;
70+
}
6471

6572
bucketsOfInterest = HashMultimap.create();
6673

src/test/java/com/urbanairship/datacube/tweetcountexample/TweetCube.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public TweetCube(DbHarness<LongOp> dbHarness, SyncLevel syncLevel) {
8484
* The DataCube defines the core logic that maps input points to database
8585
* increments.
8686
*/
87-
dataCube = new DataCube<LongOp>(dimensions, rollups, true);
87+
dataCube = new DataCube<LongOp>(dimensions, rollups, DataCube.PREFIX_MODE.MOD_ADDRESS_PREFIX);
8888

8989
/*
9090
* The DataCubeIo object connects the DataCube logic layer and the

0 commit comments

Comments
 (0)