Skip to content

Commit

Permalink
fix redis mix replicator bug
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Sep 8, 2017
1 parent 1762597 commit 4b46288
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum FileType {
* @return FileType
* @since 2.3.3
*/
public static FileType parse(String type) {
static FileType parse(String type) {
if (type == null) {
return null;
} else if (type.equalsIgnoreCase("aof")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
import com.moilioncircle.redis.replicator.cmd.CommandName;
import com.moilioncircle.redis.replicator.cmd.CommandParser;
import com.moilioncircle.redis.replicator.cmd.ReplyParser;
import com.moilioncircle.redis.replicator.io.PeekableInputStream;
import com.moilioncircle.redis.replicator.io.RedisInputStream;
import com.moilioncircle.redis.replicator.rdb.RdbParser;
import com.moilioncircle.redis.replicator.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.*;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand All @@ -38,6 +44,7 @@
public class RedisMixReplicator extends AbstractReplicator {
protected static final Log logger = LogFactory.getLog(RedisAofReplicator.class);
protected final ReplyParser replyParser;
protected final PeekableInputStream peekable;

public RedisMixReplicator(File file, Configuration configuration) throws FileNotFoundException {
this(new FileInputStream(file), configuration);
Expand All @@ -47,6 +54,11 @@ public RedisMixReplicator(InputStream in, Configuration configuration) {
Objects.requireNonNull(in);
Objects.requireNonNull(configuration);
this.configuration = configuration;
if (in instanceof PeekableInputStream) {
this.peekable = (PeekableInputStream) in;
} else {
in = this.peekable = new PeekableInputStream(in);
}
this.inputStream = new RedisInputStream(in, this.configuration.getBufferSize());
this.inputStream.setRawByteListeners(this.rawByteListeners);
this.replyParser = new ReplyParser(inputStream);
Expand All @@ -68,8 +80,10 @@ public void open() throws IOException {
}

protected void doOpen() throws IOException {
RdbParser parser = new RdbParser(inputStream, this);
parser.parse();
if (peekable.peek() == 'R') {
RdbParser parser = new RdbParser(inputStream, this);
parser.parse();
}
while (true) {
// got EOFException to break the loop
Object obj = replyParser.parse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ public int compareTo(RedisURI that) {
return this.uri.compareTo(that.uri);
}

public URL toURL() {
public URL toURL() throws MalformedURLException {
Objects.requireNonNull(getFileType());
try {
return new URI("file", uri.getRawAuthority(), uri.getRawPath(), uri.getRawQuery(), uri.getRawFragment()).toURL();
} catch (URISyntaxException | MalformedURLException e) {
throw new UnsupportedOperationException(e);
} catch (URISyntaxException e) {
throw new MalformedURLException(e.getMessage());
}
}

Expand Down

0 comments on commit 4b46288

Please sign in to comment.