Github user ilooner commented on a diff in the pull request:

    https://github.com/apache/apex-malhar/pull/345#discussion_r71095332
  
    --- Diff: 
library/src/main/java/org/apache/apex/malhar/lib/window/impl/SpillableWindowedKeyedStorage.java
 ---
    @@ -0,0 +1,136 @@
    +package org.apache.apex.malhar.lib.window.impl;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.annotation.concurrent.Immutable;
    +import javax.validation.constraints.NotNull;
    +
    +import 
org.apache.apex.malhar.lib.state.spillable.SpillableByteArrayListMultimapImpl;
    +import org.apache.apex.malhar.lib.state.spillable.SpillableByteMapImpl;
    +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.window.Window;
    +import org.apache.apex.malhar.lib.window.WindowedStorage;
    +import org.apache.commons.lang3.tuple.ImmutablePair;
    +
    +import com.datatorrent.netlet.util.Slice;
    +
    +/**
    + * Created by david on 7/15/16.
    + */
    +public class SpillableWindowedKeyedStorage<K, V> implements 
WindowedStorage.WindowedKeyedStorage<K, V>
    +{
    +  @NotNull
    +  private final ManagedStateSpillableStateStore store;
    +
    +  protected final SpillableByteMapImpl<ImmutablePair<Window, K>, V> 
internValues;
    +  protected final SpillableByteArrayListMultimapImpl<Window, K> internKeys;
    +
    +  private SpillableWindowedKeyedStorage()
    +  {
    +    // for kryo
    +    store = null;
    +    internValues = null;
    +    internKeys = null;
    +  }
    +
    +  public SpillableWindowedKeyedStorage(long bucket, byte[] identifier, 
Serde<Window, Slice> serdeWindow, Serde<K, Slice> serdeKey, 
Serde<ImmutablePair<Window, K>, Slice> serdeWindowKey, Serde<V, Slice> 
serdeValue)
    +  {
    +    store = new ManagedStateSpillableStateStore();
    +    store.getCheckpointManager().setNeedBucketFile(false);
    +    internValues = new SpillableByteMapImpl<>(store, identifier, bucket, 
serdeWindowKey, serdeValue);
    +    internKeys = new SpillableByteArrayListMultimapImpl<>(store, 
identifier, bucket, serdeWindow, serdeKey);
    +  }
    +
    +  @Override
    +  public boolean containsWindow(Window window)
    +  {
    +    return internKeys.containsKey(window);
    +  }
    +
    +  @Override
    +  public long size()
    +  {
    +    return internKeys.size();
    +  }
    +
    +  @Override
    +  public void remove(Window window)
    +  {
    +    List<K> keys = internKeys.get(window);
    +    for (K key : keys) {
    +      internValues.remove(new ImmutablePair<>(window, key));
    +    }
    +    internKeys.removeAll(window);
    +  }
    +
    +  @Override
    +  public void migrateWindow(Window fromWindow, Window toWindow)
    +  {
    +    List<K> keys = internKeys.get(fromWindow);
    +    internValues.remove(toWindow);
    +    for (K key : keys) {
    +      internKeys.put(toWindow, key);
    +      ImmutablePair<Window, K> oldKey = new ImmutablePair<>(fromWindow, 
key);
    +      ImmutablePair<Window, K> newKey = new ImmutablePair<>(toWindow, key);
    +
    +      V value = internValues.get(oldKey);
    +      internValues.remove(oldKey);
    +      internValues.put(newKey, value);
    +    }
    +    internKeys.removeAll(fromWindow);
    +  }
    +
    +  @Override
    +  public void beginApexWindow(long windowId)
    +  {
    +    store.beginWindow(windowId);
    +  }
    +
    +  @Override
    +  public void endApexWindow()
    +  {
    +    store.endWindow();
    --- End diff --
    
    spillableComplexComponent.endWindow()


---
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.
---

Reply via email to