Skip to content

Commit 03c8790

Browse files
committed
Experimental ZooKeeper based implementation
1 parent b3e4356 commit 03c8790

File tree

14 files changed

+746
-12
lines changed

14 files changed

+746
-12
lines changed

core/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<groupId>org.slf4j</groupId>
2929
<artifactId>slf4j-api</artifactId>
3030
</dependency>
31+
<dependency>
32+
<groupId>org.apache.zookeeper</groupId>
33+
<artifactId>zookeeper</artifactId>
34+
</dependency>
3135
</dependencies>
3236

3337
</project>

core/src/main/java/edu/ucsb/cs/wrench/GradesDataServer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import edu.ucsb.cs.wrench.commands.Command;
44
import edu.ucsb.cs.wrench.config.WrenchConfiguration;
55
import edu.ucsb.cs.wrench.paxos.PaxosAgent;
6+
import edu.ucsb.cs.wrench.paxos.ZKPaxosAgent;
67

7-
public class GradesDataServer extends PaxosAgent {
8+
public class GradesDataServer extends ZKPaxosAgent {
89

910
public static void main(String[] args) {
1011
final GradesDataServer server = new GradesDataServer();

core/src/main/java/edu/ucsb/cs/wrench/client/WrenchClient.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
public class WrenchClient {
1313

14+
private static final int THREADS = 1;
15+
private static final int REQUESTS = 1;
16+
1417
public static void main(String[] args) throws Exception {
15-
ClientThread[] threads = new ClientThread[1];
18+
ClientThread[] threads = new ClientThread[THREADS];
1619
for (int i = 0; i < threads.length; i++) {
1720
threads[i] = new ClientThread();
1821
}
@@ -29,7 +32,7 @@ public void run() {
2932
transport.open();
3033
TProtocol protocol = new TBinaryProtocol(transport);
3134
WrenchManagementService.Client client = new WrenchManagementService.Client(protocol);
32-
for (int i = 0; i < 100; i++) {
35+
for (int i = 0; i < REQUESTS; i++) {
3336
System.out.println(client.append(UUID.randomUUID().toString(), getName()));
3437
Thread.sleep(100);
3538
}

core/src/main/java/edu/ucsb/cs/wrench/config/WrenchConfiguration.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.apache.commons.logging.Log;
55
import org.apache.commons.logging.LogFactory;
66

7+
import java.io.File;
78
import java.io.FileInputStream;
89
import java.io.IOException;
910
import java.util.HashMap;
@@ -149,13 +150,14 @@ public static WrenchConfiguration getConfiguration() {
149150
if (config == null) {
150151
synchronized (WrenchConfiguration.class) {
151152
if (config == null) {
152-
String configPath = System.getProperty("wrench.config.file", "wrench.properties");
153+
String configPath = System.getProperty("wrench.config.dir", "conf");
153154
Properties props = new Properties();
155+
File configFile = new File(configPath, "wrench.properties");
154156
try {
155-
props.load(new FileInputStream(configPath));
157+
props.load(new FileInputStream(configFile));
156158
config = new WrenchConfiguration(props);
157159
} catch (IOException e) {
158-
String msg = "Error loading Wrench configuration from: " + configPath;
160+
String msg = "Error loading Wrench configuration from: " + configFile.getPath();
159161
log.error(msg, e);
160162
throw new WrenchException(msg, e);
161163
}

core/src/main/java/edu/ucsb/cs/wrench/messaging/WrenchManagementServiceHandler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import edu.ucsb.cs.wrench.paxos.*;
88
import org.apache.thrift.TException;
99

10-
import java.util.HashMap;
1110
import java.util.Map;
11+
import java.util.TreeMap;
1212

1313
public class WrenchManagementServiceHandler implements WrenchManagementService.Iface {
1414

15-
private PaxosAgent agent;
15+
private AgentService agent;
1616

17-
public WrenchManagementServiceHandler(PaxosAgent agent) {
17+
public WrenchManagementServiceHandler(AgentService agent) {
1818
this.agent = agent;
1919
}
2020

@@ -98,7 +98,7 @@ public void notifyAppend(String transactionId) throws TException {
9898
@Override
9999
public Map<Long,String> getPastOutcomes(long lastRequest) throws TException {
100100
Map<Long,Command> commands = agent.getPastOutcomes(lastRequest);
101-
Map<Long,String> pastOutcomes = new HashMap<Long, String>();
101+
Map<Long,String> pastOutcomes = new TreeMap<Long, String>();
102102
for (Map.Entry<Long,Command> entry : commands.entrySet()) {
103103
pastOutcomes.put(entry.getKey(), entry.getValue().toString());
104104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package edu.ucsb.cs.wrench.paxos;
2+
3+
import edu.ucsb.cs.wrench.commands.Command;
4+
import edu.ucsb.cs.wrench.config.Member;
5+
6+
import java.util.Map;
7+
8+
public interface AgentService {
9+
10+
public void onElection();
11+
12+
public void onVictory(Member member);
13+
14+
public boolean onLeaderQuery();
15+
16+
public void enqueue(PaxosEvent event);
17+
18+
public boolean executeClientRequest(Command command);
19+
20+
public Map<Long,Command> getPastOutcomes(long request);
21+
22+
public BallotNumber getNextBallotNumber();
23+
24+
}

core/src/main/java/edu/ucsb/cs/wrench/paxos/PaxosAgent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.concurrent.atomic.AtomicInteger;
2525
import java.util.concurrent.atomic.AtomicLong;
2626

27-
public abstract class PaxosAgent {
27+
public abstract class PaxosAgent implements AgentService {
2828

2929
private static final Log log = LogFactory.getLog(PaxosAgent.class);
3030

0 commit comments

Comments
 (0)