ZK-1931/javazab — pull request #3 by EasonLiao (2014-06-20 20:24:07+00:00)
Title: Define messages (using protobuf?)

Define messages based on https://cwiki.apache.org/confluence/display/ZOOKEEPER/Zab+in+words . I'm assuming we'll use protobuf, but let me know if anybody has other suggestions for serialization framework. We probably won't implement observer in v0.1, and there is no snapshot.

```
enum message {
followerinfo,
diff,
trunc,
leaderinfo,
ackepoch,
newleader,
uptodate,
proposal,
ack,
commit,
}

struct followerinfo {
int? acceptedepoch,
int protocolversion,
int serverid,
}

struct diff {
long? zxid
}

struct trunc {
long? zxid
}

struct leaderinfo {
int? proposedepoch
// What is 'protocol' in the data field?
}

struct ackepoch {
long? lastZxid
int? currentEpoch
}

struct newleader {
int? epoch
}

struct uptodate {
}

struct proposal {
long zxid
byte[] message
}

struct ack {
long? zxid
}

struct commit {
long? zxid
}
```

A few questions:

- What's the protocol field in the leaderinfo packet?
- Should the zxid be 8 byte epoch + 8 byte xid, or 4 byte epoch + 4 byte xid?
- Is there a better way to handle server IDs, like using hostname + port to identify servers? I'm not a big fan of the myid files. Using myid files does have one big advantage that the conf files are uniform across all the servers though.