func (kv *KVPaxos) isdead() bool {
	return atomic.LoadInt32(&kv.dead) != 0
}
call this to find out if the server is dead.
package kvpaxos
import "net"
import "fmt"
import "net/rpc"
import "log"
import "paxos"
import "sync"
import "sync/atomic"
import "os"
import "syscall"
import "encoding/gob"
import "math/rand"
import (
	"time"
)
const Debug = 0
func DPrintf(format string, a ...interface{}) (n int, err error) {
	if Debug > 0 {
		log.Printf(format, a...)
	}
	return
}
type Op struct {
	Op string
	ClientSeq int64
	Key string
	Value string
}
type KVPaxos struct {
	mu         sync.Mutex
	l          net.Listener
	me         int
	dead       int32  
	unreliable int32  
	px         *paxos.Paxos
	kv   		map[string]string
	seq  		map[int64]bool
	logs 		[] Op
	lastSeq 	int
	servers		[] string
}
func (kv *KVPaxos) wait(seq int) Op {
	to := 10 * time.Millisecond
	for {
		status, v := kv.px.Status(seq)
		DPrintf("%d seq %d status: %d:%d\n", kv.me, seq, status, paxos.Decided)
		if status == paxos.Decided {
			kvlog, _ := v.(Op)
			return kvlog
		}
		time.Sleep(to)
		if to < 10 * time.Second {
			to *= 2
		}
	}
}
func (kv *KVPaxos)Apply(v Op)  {
	if (v.Op != GET) {
		kv.logs = append(kv.logs, v)
		if (v.Op == PUT) {
			kv.kv[v.Key] = v.Value
		} else if v.Op == APPEND {
			old, err := kv.kv[v.Key]
			if (err) {
				kv.kv[v.Key] = old + v.Value
			} else {
				kv.kv[v.Key] = v.Value
			}
		}
	}
	kv.seq[v.ClientSeq] = true
	kv.px.Done(kv.lastSeq)
	kv.lastSeq += 1
}
func (kv *KVPaxos) ProcessOperation(v Op) {
	ok := false
	var log Op
	for !ok {
		seq := kv.lastSeq
		status, val := kv.px.Status(kv.lastSeq)
		if status == paxos.Decided {
			log = val.(Op)
		} else {
			kv.px.Start(seq, v)
			log = kv.wait(seq)
		}
		ok = v.ClientSeq == log.ClientSeq
		kv.Apply(log)
	}
}
func (kv *KVPaxos) Get(args *GetArgs, reply *GetReply) error {
	kv.mu.Lock()
	defer kv.mu.Unlock()
	var v Op = Op{Op:GET, Key:args.Key, ClientSeq:args.Seq}
	kv.ProcessOperation(v)
	val, ok := kv.kv[v.Key]
	if !ok {
		reply.Err = ErrNoKey
	} else {
		reply.Err = OK
		reply.Value = val
	}
	return nil
}
func (kv *KVPaxos) PutAppend(args *PutAppendArgs, reply *PutAppendReply) error {
	kv.mu.Lock()
	defer kv.mu.Unlock()
	_, exist := kv.seq[args.Seq]
	if (exist) {
		reply.Err = OK
		return nil
	}
	appendOp := Op{Op:args.Op, ClientSeq:args.Seq, Key:args.Key, Value:args.Value}
	kv.ProcessOperation(appendOp)
	DPrintf("%d %s %s:%s done\n", kv.me, args.Op, args.Key, args.Value)
	return nil
}
func (kv *KVPaxos) kill() {
	DPrintf("Kill(%d): die\n", kv.me)
	atomic.StoreInt32(&kv.dead, 1)
	kv.l.Close()
	kv.px.Kill()
}