[GitHub] apex-malhar pull request #345: APEXMALHAR-2130 REVIEW ONLY (WindowedOperator...

2016-09-22 Thread davidyan74
Github user davidyan74 closed the pull request at:

https://github.com/apache/apex-malhar/pull/345


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] apex-malhar pull request #345: APEXMALHAR-2130 REVIEW ONLY (WindowedOperator...

2016-08-01 Thread davidyan74
Github user davidyan74 closed the pull request at:

https://github.com/apache/apex-malhar/pull/345


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] apex-malhar pull request #345: APEXMALHAR-2130 REVIEW ONLY (WindowedOperator...

2016-07-27 Thread davidyan74
Github user davidyan74 commented on a diff in the pull request:

https://github.com/apache/apex-malhar/pull/345#discussion_r72521168
  
--- Diff: 
library/src/test/java/org/apache/apex/malhar/lib/window/SpillableWindowedStorageTest.java
 ---
@@ -0,0 +1,122 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.apex.malhar.lib.window;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.apex.malhar.lib.state.spillable.SpillableTestUtils;
+import 
org.apache.apex.malhar.lib.window.impl.SpillableWindowedKeyedStorage;
+import 
org.apache.apex.malhar.lib.window.impl.SpillableWindowedPlainStorage;
+
+import com.datatorrent.lib.util.KryoCloneUtils;
+
+/**
+ * Unit tests for Spillable Windowed Storage
+ */
+public class SpillableWindowedStorageTest
+{
+  @Rule
+  public SpillableTestUtils.TestMeta testMeta = new 
SpillableTestUtils.TestMeta();
+
+  @Ignore
+  @Test
+  public void testWindowedPlainStorage()
+  {
+SpillableWindowedPlainStorage storage = new 
SpillableWindowedPlainStorage<>();
+Window window1 = new Window.TimeWindow<>(1000, 10);
+Window window2 = new Window.TimeWindow<>(1010, 10);
+Window window3 = new Window.TimeWindow<>(1020, 10);
+storage.setStore(testMeta.store);
+storage.setup(testMeta.operatorContext);
+storage.beginApexWindow(1000);
+storage.put(window1, 1);
+storage.put(window2, 2);
+storage.put(window3, 3);
+storage.endApexWindow();
+storage.beginApexWindow(1001);
+storage.put(window1, 4);
+storage.put(window2, 5);
+storage.endApexWindow();
+storage.beforeCheckpoint(1001);
+storage.checkpointed(1001);
+
+SpillableWindowedPlainStorage clonedStorage = 
KryoCloneUtils.cloneObject(storage);
+
+storage.beginApexWindow(1002);
+storage.put(window1, 6);
+storage.put(window2, 7);
+storage.endApexWindow();
+
+Assert.assertEquals(6L, storage.get(window1).longValue());
+Assert.assertEquals(7L, storage.get(window2).longValue());
+Assert.assertEquals(3L, storage.get(window3).longValue());
+
+storage.beginApexWindow(1003);
+storage.put(window1, 8);
+storage.put(window2, 9);
+storage.endApexWindow();
+
+// simulating crash here
+storage.teardown();
+
+storage = clonedStorage;
+storage.setup(testMeta.operatorContext);
+
--- End diff --

@ilooner I made both SpillableComplexComponentImpl and SpillableByteMap 
non-transient and made the necessary changes to have them serializable by kryo. 
Take a look at the commit a71d2cc. But it looks like the data is still not 
fetched from disk after the recovery.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] apex-malhar pull request #345: APEXMALHAR-2130 REVIEW ONLY (WindowedOperator...

2016-07-27 Thread davidyan74
Github user davidyan74 commented on a diff in the pull request:

https://github.com/apache/apex-malhar/pull/345#discussion_r72494611
  
--- Diff: 
library/src/main/java/org/apache/apex/malhar/lib/window/impl/SpillableWindowedPlainStorage.java
 ---
@@ -0,0 +1,188 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.apex.malhar.lib.window.impl;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.apex.malhar.lib.state.spillable.Spillable;
+import 
org.apache.apex.malhar.lib.state.spillable.SpillableComplexComponentImpl;
+import org.apache.apex.malhar.lib.state.spillable.SpillableStateStore;
+import 
org.apache.apex.malhar.lib.state.spillable.managed.ManagedStateSpillableStateStore;
+import org.apache.apex.malhar.lib.utils.serde.Serde;
+import org.apache.apex.malhar.lib.utils.serde.SerdeKryoSlice;
+import org.apache.apex.malhar.lib.window.Window;
+import org.apache.apex.malhar.lib.window.WindowedStorage;
+
+import com.datatorrent.api.Context;
+import com.datatorrent.netlet.util.Slice;
+
+/**
+ * This is an implementation of WindowedPlainStorage that makes use of 
{@link Spillable} data structures
+ *
+ * @param  Type of the value per window
+ */
+public class SpillableWindowedPlainStorage implements 
WindowedStorage.WindowedPlainStorage
+{
+  private SpillableStateStore store;
+  private transient SpillableComplexComponentImpl sccImpl;
+  private long bucket;
+  private Serde windowSerde;
+  private Serde valueSerde;
+
+  protected transient Spillable.SpillableByteMap internMap;
+
+  public SpillableWindowedPlainStorage()
+  {
+  }
+
+  public SpillableWindowedPlainStorage(long bucket, Serde 
windowSerde, Serde valueSerde)
+  {
+this.bucket = bucket;
+this.windowSerde = windowSerde;
+this.valueSerde = valueSerde;
+  }
+
+  public void setStore(SpillableStateStore store)
+  {
+this.store = store;
+  }
+
+  public void setBucket(long bucket)
+  {
+this.bucket = bucket;
+  }
+
+  public void setWindowSerde(Serde windowSerde)
+  {
+this.windowSerde = windowSerde;
+  }
+
+  public void setValueSerde(Serde valueSerde)
+  {
+this.valueSerde = valueSerde;
+  }
+
+  @Override
+  public void put(Window window, T value)
+  {
+internMap.put(window, value);
+  }
+
+  @Override
+  public T get(Window window)
+  {
+return internMap.get(window);
+  }
+
+  @Override
+  public Iterable> entrySet()
+  {
+return internMap.entrySet();
+  }
+
+  @Override
+  public Iterator> iterator()
+  {
+return internMap.entrySet().iterator();
+  }
+
+  @Override
+  public boolean containsWindow(Window window)
+  {
+return internMap.containsKey(window);
+  }
+
+  @Override
+  public long size()
+  {
+return internMap.size();
+  }
+
+  @Override
+  public void remove(Window window)
+  {
+internMap.remove(window);
+  }
+
+  @Override
+  public void migrateWindow(Window fromWindow, Window toWindow)
+  {
+internMap.put(toWindow, internMap.remove(fromWindow));
+  }
+
+  @Override
+  public void setup(Context.OperatorContext context)
+  {
+if (store == null) {
+  // provide a default store
+  store = new ManagedStateSpillableStateStore();
+}
+if (bucket == 0) {
+  // choose a bucket that is almost guaranteed to be unique
+  bucket = (context.getValue(Context.DAGContext.APPLICATION_NAME) + 
"#" + context.getId()).hashCode();
+}
+// set default serdes
+if (windowSerde == null) {
+  windowSerde = new SerdeKryoSlice<>();
+}
+if 

[GitHub] apex-malhar pull request #345: APEXMALHAR-2130 REVIEW ONLY (WindowedOperator...

2016-07-27 Thread ilooner
Github user ilooner commented on a diff in the pull request:

https://github.com/apache/apex-malhar/pull/345#discussion_r72389548
  
--- Diff: 
library/src/main/java/org/apache/apex/malhar/lib/window/impl/SpillableWindowedPlainStorage.java
 ---
@@ -0,0 +1,188 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.apex.malhar.lib.window.impl;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.apex.malhar.lib.state.spillable.Spillable;
+import 
org.apache.apex.malhar.lib.state.spillable.SpillableComplexComponentImpl;
+import org.apache.apex.malhar.lib.state.spillable.SpillableStateStore;
+import 
org.apache.apex.malhar.lib.state.spillable.managed.ManagedStateSpillableStateStore;
+import org.apache.apex.malhar.lib.utils.serde.Serde;
+import org.apache.apex.malhar.lib.utils.serde.SerdeKryoSlice;
+import org.apache.apex.malhar.lib.window.Window;
+import org.apache.apex.malhar.lib.window.WindowedStorage;
+
+import com.datatorrent.api.Context;
+import com.datatorrent.netlet.util.Slice;
+
+/**
+ * This is an implementation of WindowedPlainStorage that makes use of 
{@link Spillable} data structures
+ *
+ * @param  Type of the value per window
+ */
+public class SpillableWindowedPlainStorage implements 
WindowedStorage.WindowedPlainStorage
+{
+  private SpillableStateStore store;
+  private transient SpillableComplexComponentImpl sccImpl;
+  private long bucket;
+  private Serde windowSerde;
+  private Serde valueSerde;
+
+  protected transient Spillable.SpillableByteMap internMap;
+
+  public SpillableWindowedPlainStorage()
+  {
+  }
+
+  public SpillableWindowedPlainStorage(long bucket, Serde 
windowSerde, Serde valueSerde)
+  {
+this.bucket = bucket;
+this.windowSerde = windowSerde;
+this.valueSerde = valueSerde;
+  }
+
+  public void setStore(SpillableStateStore store)
+  {
+this.store = store;
+  }
+
+  public void setBucket(long bucket)
+  {
+this.bucket = bucket;
+  }
+
+  public void setWindowSerde(Serde windowSerde)
+  {
+this.windowSerde = windowSerde;
+  }
+
+  public void setValueSerde(Serde valueSerde)
+  {
+this.valueSerde = valueSerde;
+  }
+
+  @Override
+  public void put(Window window, T value)
+  {
+internMap.put(window, value);
+  }
+
+  @Override
+  public T get(Window window)
+  {
+return internMap.get(window);
+  }
+
+  @Override
+  public Iterable> entrySet()
+  {
+return internMap.entrySet();
+  }
+
+  @Override
+  public Iterator> iterator()
+  {
+return internMap.entrySet().iterator();
+  }
+
+  @Override
+  public boolean containsWindow(Window window)
+  {
+return internMap.containsKey(window);
+  }
+
+  @Override
+  public long size()
+  {
+return internMap.size();
+  }
+
+  @Override
+  public void remove(Window window)
+  {
+internMap.remove(window);
+  }
+
+  @Override
+  public void migrateWindow(Window fromWindow, Window toWindow)
+  {
+internMap.put(toWindow, internMap.remove(fromWindow));
+  }
+
+  @Override
+  public void setup(Context.OperatorContext context)
+  {
+if (store == null) {
+  // provide a default store
+  store = new ManagedStateSpillableStateStore();
+}
+if (bucket == 0) {
+  // choose a bucket that is almost guaranteed to be unique
+  bucket = (context.getValue(Context.DAGContext.APPLICATION_NAME) + 
"#" + context.getId()).hashCode();
+}
+// set default serdes
+if (windowSerde == null) {
+  windowSerde = new SerdeKryoSlice<>();
+}
+if