Skip to content

Commit a2e23a1

Browse files
author
Ben Osheroff
committed
Merge pull request zendesk#192 from zendesk/ben/fix_memory_issues_again
take another try at preventing memory issues.
2 parents e5f85eb + c0accf3 commit a2e23a1

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/main/java/com/zendesk/maxwell/MaxwellReplicator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ private RowMapBuffer getTransactionRows() throws Exception {
160160

161161
RowMapBuffer buffer = new RowMapBuffer(MAX_TX_ELEMENTS);
162162

163-
// currently to satisfy the test interface, the contract is to return null
164-
// if the queue is empty. should probably just replace this with an optional timeout...
165-
166163
while ( true ) {
167164
v4Event = pollV4EventFromQueue();
165+
166+
// currently to satisfy the test interface, the contract is to return null
167+
// if the queue is empty. should probably just replace this with an optional timeout...
168168
if (v4Event == null) {
169169
ensureReplicatorThread();
170170
continue;

src/main/java/com/zendesk/maxwell/util/ListWithDiskBuffer.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public void add(T element) throws IOException {
3131
if ( file == null ) {
3232
file = File.createTempFile("maxwell", "events");
3333
file.deleteOnExit();
34-
os = new ObjectOutputStream(new FileOutputStream(file));
35-
is = new ObjectInputStream(new FileInputStream(file));
34+
os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
3635
}
3736

3837
if ( elementsInFile == 0 )
3938
LOGGER.debug("Overflowed in-memory buffer, spilling over into " + file);
4039

41-
os.writeObject(this.list.removeFirst());
40+
os.writeUnshared(this.list.removeFirst());
41+
4242
elementsInFile++;
4343
}
4444
}
@@ -52,8 +52,13 @@ public T getLast() {
5252
}
5353

5454
public T removeFirst() throws IOException, ClassNotFoundException {
55-
if ( elementsInFile > 0 && is != null ) {
56-
T element = (T) is.readObject();
55+
if ( elementsInFile > 0 ) {
56+
if ( is == null ) {
57+
os.flush();
58+
is = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
59+
}
60+
61+
T element = (T) is.readUnshared();
5762
elementsInFile--;
5863
return element;
5964
} else {

0 commit comments

Comments
 (0)