From 0ba72f008f06383358877f4fe1c6bded33293769 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Fri, 28 Oct 2016 08:48:56 -0400 Subject: [PATCH 1/3] create persistent sequential node with empty bytes --- .../hubspot/baragon/data/AbstractDataStore.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java b/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java index eb7e8500a..89a1e31d5 100644 --- a/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java +++ b/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java @@ -128,14 +128,15 @@ protected byte[] serialize(T data) { protected Optional readFromZk(final String path, final Class klass) { final long start = System.currentTimeMillis(); - return readFromZk(path).transform(new Function() { + Optional data = readFromZk(path); - @Override - public T apply(byte[] data) { - log(OperationType.READ, Optional.absent(), Optional.of(data.length), start, path); - return deserialize(data, klass, path); + if (data.isPresent()) { + log(OperationType.READ, Optional.absent(), Optional.of(data.get().length), start, path); + if (data.get().length > 0) { + return Optional.of(deserialize(data.get(), klass, path)); } - }); + } + return Optional.absent(); } protected Optional readFromZk(String path) { @@ -184,7 +185,7 @@ protected String createPersistentSequentialNode(String path) { final long start = System.currentTimeMillis(); try { - final String result = curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path); + final String result = curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path, new byte[] {}); log(OperationType.WRITE, Optional.absent(), Optional.absent(), start, path); return result; } catch (Exception e) { From 369cd8c5cb24a485532c6a265eb0cf52fa14726c Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Mon, 31 Oct 2016 09:23:58 -0400 Subject: [PATCH 2/3] set default data for curator framework --- .../com/hubspot/baragon/data/AbstractDataStore.java | 2 +- .../baragon/service/BaragonServiceModule.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java b/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java index 89a1e31d5..0522fe8b5 100644 --- a/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java +++ b/BaragonData/src/main/java/com/hubspot/baragon/data/AbstractDataStore.java @@ -185,7 +185,7 @@ protected String createPersistentSequentialNode(String path) { final long start = System.currentTimeMillis(); try { - final String result = curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path, new byte[] {}); + final String result = curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path); log(OperationType.WRITE, Optional.absent(), Optional.absent(), start, path); return result; } catch (Exception e) { diff --git a/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java b/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java index 626b46c7b..6df92e006 100644 --- a/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java +++ b/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java @@ -226,11 +226,13 @@ public AmazonElasticLoadBalancingClient providesAwsElbClient(Optional Date: Mon, 31 Oct 2016 09:36:08 -0400 Subject: [PATCH 3/3] byte[0] --- .../java/com/hubspot/baragon/service/BaragonServiceModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java b/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java index 6df92e006..85b2bc9d4 100644 --- a/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java +++ b/BaragonService/src/main/java/com/hubspot/baragon/service/BaragonServiceModule.java @@ -231,7 +231,7 @@ public CuratorFramework provideCurator(ZooKeeperConfiguration config, BaragonCon .sessionTimeoutMs(config.getSessionTimeoutMillis()) .connectionTimeoutMs(config.getConnectTimeoutMillis()) .retryPolicy(new ExponentialBackoffRetry(config.getRetryBaseSleepTimeMilliseconds(), config.getRetryMaxTries())) - .defaultData(new byte[] {}) + .defaultData(new byte[0]) .build(); client.getConnectionStateListenable().addListener(connectionStateListener);