From 79e14c2be1cd8993c3fdcd550768094dae34fa85 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 27 Aug 2014 21:15:18 -0700 Subject: [PATCH] WriteCommand -> ExecuteCommand --- .../{write_command.go => execute_command.go} | 26 +++++++++---------- src/github.com/otoolep/rqlite/main.go | 4 +-- .../otoolep/rqlite/server/server.go | 4 +-- 3 files changed, 17 insertions(+), 17 deletions(-) rename src/github.com/otoolep/rqlite/command/{write_command.go => execute_command.go} (66%) diff --git a/src/github.com/otoolep/rqlite/command/write_command.go b/src/github.com/otoolep/rqlite/command/execute_command.go similarity index 66% rename from src/github.com/otoolep/rqlite/command/write_command.go rename to src/github.com/otoolep/rqlite/command/execute_command.go index 4ad8edb2..94fd0104 100644 --- a/src/github.com/otoolep/rqlite/command/write_command.go +++ b/src/github.com/otoolep/rqlite/command/execute_command.go @@ -8,51 +8,51 @@ import ( ) // This command encapsulates a sqlite statement. -type WriteCommand struct { +type ExecuteCommand struct { Stmt string `json:"stmt"` } // Creates a new write command. -func NewWriteCommand(stmt string) *WriteCommand { - return &WriteCommand{ +func NewExecuteCommand(stmt string) *ExecuteCommand { + return &ExecuteCommand{ Stmt: stmt, } } // The name of the command in the log. -func (c *WriteCommand) CommandName() string { +func (c *ExecuteCommand) CommandName() string { return "write" } // Executes an sqlite statement. -func (c *WriteCommand) Apply(server raft.Server) (interface{}, error) { - log.Trace("Applying WriteCommand: '%s'", c.Stmt) +func (c *ExecuteCommand) Apply(server raft.Server) (interface{}, error) { + log.Trace("Applying ExecuteCommand: '%s'", c.Stmt) db := server.Context().(*db.DB) return nil, db.Execute(c.Stmt) } // This command encapsulates a set of sqlite statement, which are executed // within a transaction. -type TransactionWriteCommandSet struct { +type TransactionExecuteCommandSet struct { Stmts []string `json:"stmts"` } // Creates a new set of sqlite commands, which execute within a transaction. -func NewTransactionWriteCommandSet(stmts []string) *TransactionWriteCommandSet { - return &TransactionWriteCommandSet{ +func NewTransactionExecuteCommandSet(stmts []string) *TransactionExecuteCommandSet { + return &TransactionExecuteCommandSet{ Stmts: stmts, } } // The name of the command in the log. -func (c *TransactionWriteCommandSet) CommandName() string { - return "transaction_write" +func (c *TransactionExecuteCommandSet) CommandName() string { + return "transaction_execute" } // Executes a set of sqlite statements, within a transaction. All statements // will take effect, or none. -func (c *TransactionWriteCommandSet) Apply(server raft.Server) (interface{}, error) { - log.Trace("Applying TransactionWriteCommandSet of size %d", len(c.Stmts)) +func (c *TransactionExecuteCommandSet) Apply(server raft.Server) (interface{}, error) { + log.Trace("Applying TransactionExecuteCommandSet of size %d", len(c.Stmts)) db := server.Context().(*db.DB) err := db.StartTransaction() diff --git a/src/github.com/otoolep/rqlite/main.go b/src/github.com/otoolep/rqlite/main.go index d52b0b3a..f01b28b7 100644 --- a/src/github.com/otoolep/rqlite/main.go +++ b/src/github.com/otoolep/rqlite/main.go @@ -99,8 +99,8 @@ func main() { rand.Seed(time.Now().UnixNano()) // Setup commands. - raft.RegisterCommand(&command.WriteCommand{}) - raft.RegisterCommand(&command.TransactionWriteCommandSet{}) + raft.RegisterCommand(&command.ExecuteCommand{}) + raft.RegisterCommand(&command.TransactionExecuteCommandSet{}) // Set the data directory. if flag.NArg() == 0 { diff --git a/src/github.com/otoolep/rqlite/server/server.go b/src/github.com/otoolep/rqlite/server/server.go index e9bcafce..ab710760 100644 --- a/src/github.com/otoolep/rqlite/server/server.go +++ b/src/github.com/otoolep/rqlite/server/server.go @@ -268,7 +268,7 @@ func (s *Server) writeHandler(w http.ResponseWriter, req *http.Request) { transaction, _ := isTransaction(req) if transaction { log.Trace("Transaction requested") - _, err = s.raftServer.Do(command.NewTransactionWriteCommandSet(stmts)) + _, err = s.raftServer.Do(command.NewTransactionExecuteCommandSet(stmts)) if err != nil { failures = append(failures, FailedSqlStmt{stmts[0], err.Error()}) log.Trace("Transaction failed: %s", err.Error()) @@ -276,7 +276,7 @@ func (s *Server) writeHandler(w http.ResponseWriter, req *http.Request) { } else { log.Trace("No transaction requested") for i := range stmts { - _, err = s.raftServer.Do(command.NewWriteCommand(stmts[i])) + _, err = s.raftServer.Do(command.NewExecuteCommand(stmts[i])) if err != nil { log.Trace("Execute statement %s failed: %s", stmts[i], err.Error()) failures = append(failures, FailedSqlStmt{stmts[i], err.Error()})