-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ian UI d2 1728 identity buckets oom #492
Open
Ian-Nara
wants to merge
14
commits into
main
Choose a base branch
from
ian-UID2-1728-identity-buckets-oom
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cb479e9
limit number of entries returned.
Ian-Nara a4eea10
return buckets in chunks of 30000
Ian-Nara 758f094
Configurable identity buckets chunk size
Ian-Nara 5dd3332
tests, refactoring, encryption
Ian-Nara d36c702
update v1 buckets
Ian-Nara 8f51843
undo unnecessary whitespace change
Ian-Nara 3962d98
undo unnecessary whitespace change
Ian-Nara 0e69b2f
undo unnecessary whitespace change
Ian-Nara 75fbfcf
undo unnecessary whitespace change
Ian-Nara 8e52064
3 part stream
Ian-Nara 400d7ad
refactoring
Ian-Nara 4f0bbf7
rename interface
Ian-Nara a8e4506
fixed concurrency bug
Ian-Nara 73b06e7
refactoring, strengthening tests
Ian-Nara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/com/uid2/operator/service/IModifiedBucketEncryptStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.uid2.operator.service; | ||
|
||
import io.vertx.core.AsyncResult; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.streams.Pipe; | ||
import io.vertx.core.streams.ReadStream; | ||
import io.vertx.core.streams.WriteStream; | ||
|
||
public interface IModifiedBucketEncryptStream extends ReadStream<Buffer>, WriteStream<Buffer> { | ||
IModifiedBucketEncryptStream exceptionHandler(Handler<Throwable> handler); | ||
|
||
Future<Void> write(Buffer buffer); | ||
|
||
void write(Buffer buffer, Handler<AsyncResult<Void>> handler); | ||
|
||
void end(Handler<AsyncResult<Void>> handler); | ||
|
||
WriteStream<Buffer> setWriteQueueMaxSize(int i); | ||
|
||
boolean writeQueueFull(); | ||
|
||
WriteStream<Buffer> drainHandler(Handler<Void> handler); | ||
|
||
ReadStream<Buffer> handler(Handler<Buffer> handler); | ||
|
||
ReadStream<Buffer> pause(); | ||
|
||
ReadStream<Buffer> resume(); | ||
|
||
ReadStream<Buffer> fetch(long l); | ||
|
||
ReadStream<Buffer> endHandler(Handler<Void> handler); | ||
|
||
@Override | ||
default Pipe<Buffer> pipe() { | ||
return ReadStream.super.pipe(); | ||
} | ||
|
||
@Override | ||
default Future<Void> pipeTo(WriteStream<Buffer> dst) { | ||
return ReadStream.super.pipeTo(dst); | ||
} | ||
|
||
@Override | ||
default void pipeTo(WriteStream<Buffer> dst, Handler<AsyncResult<Void>> handler) { | ||
ReadStream.super.pipeTo(dst, handler); | ||
} | ||
} |
195 changes: 195 additions & 0 deletions
195
src/main/java/com/uid2/operator/service/ModifiedBucketEncodeStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package com.uid2.operator.service; | ||
|
||
import com.uid2.shared.Utils; | ||
import io.vertx.core.AsyncResult; | ||
import io.vertx.core.Context; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.streams.ReadStream; | ||
import io.vertx.core.streams.WriteStream; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Arrays; | ||
|
||
|
||
public class ModifiedBucketEncodeStream implements IModifiedBucketEncryptStream { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ModifiedBucketEncodeStream.class); | ||
|
||
private final Context context; | ||
|
||
private Handler<Throwable> exceptionHandler; | ||
private Handler<Void> endHandler; | ||
private Handler<Buffer> dataHandler; | ||
private Handler<Void> drainHandler; | ||
|
||
private boolean readInProgress; | ||
private boolean incomingStreamEnded = false; | ||
private boolean outgoingStreamEnded = false; | ||
private long maxBufferSizeBytes = 5242880; // 5 MB | ||
private long demand = Long.MAX_VALUE; | ||
|
||
Buffer data; | ||
|
||
public ModifiedBucketEncodeStream(Context context) { | ||
this.context = context; | ||
this.data = Buffer.buffer(); | ||
} | ||
|
||
@Override | ||
public synchronized IModifiedBucketEncryptStream exceptionHandler(Handler<Throwable> handler) { | ||
this.exceptionHandler = handler; | ||
return this; | ||
} | ||
|
||
@Override | ||
public synchronized Future<Void> write(Buffer buffer) { | ||
synchronized (this) { | ||
data.appendBuffer(buffer); | ||
} | ||
return Future.succeededFuture(); | ||
} | ||
|
||
@Override | ||
public synchronized void write(Buffer buffer, Handler<AsyncResult<Void>> handler) { | ||
synchronized (this) { | ||
data.appendBuffer(buffer); | ||
} | ||
succeededAsyncResult(handler); | ||
} | ||
|
||
private void succeededAsyncResult(Handler<AsyncResult<Void>> handler) { | ||
handler.handle(new AsyncResult<>() { | ||
@Override | ||
public Void result() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Throwable cause() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean succeeded() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean failed() { | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public synchronized void end(Handler<AsyncResult<Void>> handler) { | ||
this.incomingStreamEnded = true; | ||
succeededAsyncResult(handler); | ||
} | ||
|
||
@Override | ||
public synchronized WriteStream<Buffer> setWriteQueueMaxSize(int i) { | ||
maxBufferSizeBytes = i; | ||
return this; | ||
} | ||
|
||
@Override | ||
public synchronized boolean writeQueueFull() { | ||
return data.length() > maxBufferSizeBytes; | ||
} | ||
|
||
@Override | ||
public synchronized WriteStream<Buffer> drainHandler(Handler<Void> handler) { | ||
this.drainHandler = handler; | ||
return this; | ||
} | ||
|
||
// ReadStream methods | ||
|
||
@Override | ||
public synchronized ReadStream<Buffer> handler(Handler<Buffer> handler) { | ||
this.dataHandler = handler; | ||
if (handler != null && demand > 0) { | ||
read(); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public synchronized ReadStream<Buffer> pause() { | ||
this.demand = 0; | ||
return this; | ||
} | ||
|
||
@Override | ||
public synchronized ReadStream<Buffer> resume() { | ||
fetch(Long.MAX_VALUE); | ||
return this; | ||
} | ||
|
||
@Override | ||
public synchronized ReadStream<Buffer> fetch(long amount) { | ||
demand = Long.MAX_VALUE - amount >= demand ? demand + amount : Long.MAX_VALUE; | ||
read(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public synchronized ReadStream<Buffer> endHandler(Handler<Void> handler) { | ||
this.endHandler = handler; | ||
return this; | ||
} | ||
|
||
private void read() { | ||
if (this.readInProgress) { | ||
if (!incomingStreamEnded || !outgoingStreamEnded) { | ||
this.context.runOnContext(v -> this.read()); | ||
} | ||
return; | ||
} | ||
|
||
if (demand <= 0) { | ||
return; | ||
} | ||
demand--; | ||
|
||
this.readInProgress = true; | ||
|
||
this.context.executeBlocking(() -> { | ||
String chunk = ""; | ||
if (data.length() == 0) { | ||
return chunk; | ||
} | ||
|
||
synchronized (this) { | ||
if (data.length() % 3 == 0 || incomingStreamEnded) { | ||
chunk = Utils.toBase64String(data.getBytes()); | ||
data = Buffer.buffer(); | ||
outgoingStreamEnded = true; | ||
} else if ((data.length() - 1) % 3 == 0) { | ||
chunk = Utils.toBase64String(Arrays.copyOfRange(data.getBytes(), 0, data.length() - 1)); | ||
data = Buffer.buffer(Arrays.copyOfRange(data.getBytes(), data.length() - 1, data.length())); | ||
} else { | ||
chunk = Utils.toBase64String(Arrays.copyOfRange(data.getBytes(), 0, data.length() - 2)); | ||
data = Buffer.buffer(Arrays.copyOfRange(data.getBytes(), data.length() - 2, data.length())); | ||
} | ||
return chunk; | ||
} | ||
}, asyncResult -> { | ||
this.dataHandler.handle(Buffer.buffer(asyncResult.result())); | ||
this.readInProgress = false; | ||
scheduleNextRead(); | ||
}); | ||
} | ||
|
||
private synchronized void scheduleNextRead() { | ||
if (demand > 0 && (!incomingStreamEnded || !outgoingStreamEnded)) { | ||
context.runOnContext(unused -> read()); | ||
} else if (outgoingStreamEnded && endHandler != null) { | ||
endHandler.handle(null); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to check
UID2 Java Coding Guidelines
in conf