-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add handler metrics to bus and saga (#101) * add handler metrics to bus and saga + tests * fix build * add 0 to the default buckets to catch fast message handling * PR correction - changed latency to summary(removed bucket configuration), add registration for saga handlers * PR correction - getting logger as a param * PR correction - new line in eof * PR corrections message handler + sync.map + latency as summary * add rejected messages metric * dead letter handler should reject messages on failures and rollbacks and ack on commit success (#105) * dead letter handler should reject messages on failures and rollbacks * dead letter handler should reject messages on failures and rollbacks * dead letter handler should reject messages on failures and rollbacks * dead letter handler should reject messages on failures and rollbacks * return an error from the saga store when deleting a saga if saga can not (#110) be found In order to deal with concurrent deletes of the sage saga instance we would wan't to indicate that deleting the saga failed if the saga is not stored so callers can take proper action * Persisted timeouts (#107) * decouple transaction manager from glue * moved timeout manager to gbus/tx package * initial commit in order to support persisted timeouts * first working version of a mysql persisted timeout manager * fixing ci lint errors * refactored ensure schema of timeout manager * cleanup timeout manager when bs shuts down * fixing formatting issues * changed logging level from Info to Debug when inserting a new timeout * resusing timeouts tablename (PR review) * renamed AcceptTimeoutFunction to SetTimeoutFunction on the TimeoutManager interface (PR review) * refactored glue to implement the Logged inetrface and use the GLogged helper struct * locking timeout record before executing timeout In order to prevent having a timeout beeing executed twice due to two concurrent grabbit instances running the same service a lock (FOR UPDATE) has been placed on the timeout record in the scope of the executing transaction * Commiting the select transaction when querying for pending timeouts * feat(timeout:lock): This is done in order to reduce contention and allow for parallel processing in case of multiple grabbit instances * Enable returning a message back from the dead to the queue (#112) * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * enable sending raw messages * return to q * return to q * return to q * return to q * return dead to q * allow no retries * test - resend dead to queue * test - resend dead to queue * test - resend dead to queue * test - resend dead to queue - fixes after cr * test - resend dead to queue - fixes after cr * test - resend dead to queue - fixes after cr * added metric report on saga timeout (#114) 1) added reporting saga timeouts to the glue component 2) fixed mysql timeoutmanager error when trying to clear a timeout * Added documentation for grabbit metrics (#117) * added initial documentation for grabbit metrics * including metrics section in readme.md * fixing goreportcard issues (#118) * removed logging a warning when worker message channel returns an error (#116) * corrected saga metrics name and added to metrics documentation (#119) * corrected saga metrics name and added documentatio * corrected saga metric name * corrected typos * removed non transactional bus mode (#120) * remove fields * remove fields * go fmt and go lint error fixes to improve goreportcard (#126) * go fmt on some files * go fmt * added comments on exported types * cunsume the messages channel via ranging over the channel to prevent (#125) empty delivreies * Migrations functionality (#111) * implement migrations * implement migrations * implement migrations * implement migrations * implement migrations * migrations * migrations * migrations * migrations * migrations * migrations * migrations * fix tests error * add migrations * migrations - timeout table migration * test - resend dead to queue - fixes after cr * migraration to grabbit (use forked migrator) * remove fields * remove fields * remove fields * remove fields * touch
- Loading branch information
Guy Baron
committed
Aug 18, 2019
1 parent
31d9fc5
commit 253ae5d
Showing
20 changed files
with
191 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package mysql | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"fmt" | ||
"github.com/lopezator/migrator" | ||
"github.com/wework/grabbit/gbus/tx" | ||
) | ||
|
||
//SagaStoreTableMigration creates the service saga store table | ||
func SagaStoreTableMigration(svcName string) *migrator.Migration { | ||
tblName := tx.GetSagatableName(svcName) | ||
|
||
createTableQuery := `CREATE TABLE IF NOT EXISTS ` + tblName + ` ( | ||
rec_id INT PRIMARY KEY AUTO_INCREMENT, | ||
saga_id VARCHAR(255) UNIQUE NOT NULL, | ||
saga_type VARCHAR(255) NOT NULL, | ||
saga_data LONGBLOB NOT NULL, | ||
version integer NOT NULL DEFAULT 0, | ||
last_update timestamp DEFAULT NOW(), | ||
INDEX ` + tblName + `_sagatype_idx (saga_type))` | ||
|
||
return &migrator.Migration{ | ||
Name: "create saga store table", | ||
Func: func(tx *sql.Tx) error { | ||
if _, err := tx.Exec(createTableQuery); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
//OutboxMigrations creates service outbox table | ||
func OutboxMigrations(svcName string) *migrator.Migration { | ||
|
||
query := `CREATE TABLE IF NOT EXISTS ` + getOutboxName(svcName) + ` ( | ||
rec_id int NOT NULL AUTO_INCREMENT, | ||
message_id varchar(50) NOT NULL UNIQUE, | ||
message_type varchar(50) NOT NULL, | ||
exchange varchar(50) NOT NULL, | ||
routing_key varchar(50) NOT NULL, | ||
publishing longblob NOT NULL, | ||
status int(11) NOT NULL, | ||
relay_id varchar(50) NULL, | ||
delivery_tag bigint(20) NOT NULL, | ||
delivery_attempts int NOT NULL DEFAULT 0, | ||
insert_date timestamp DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY(rec_id), | ||
INDEX status_delivery (rec_id, status, delivery_attempts))` | ||
|
||
return &migrator.Migration{ | ||
Name: "create outbox table", | ||
Func: func(tx *sql.Tx) error { | ||
if _, err := tx.Exec(query); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
//TimoutTableMigration creates the service timeout table, where timeouts are persisted | ||
func TimoutTableMigration(svcName string) *migrator.Migration { | ||
tblName := GetTimeoutsTableName(svcName) | ||
|
||
createTableQuery := `CREATE TABLE IF NOT EXISTS ` + tblName + ` ( | ||
rec_id INT PRIMARY KEY AUTO_INCREMENT, | ||
saga_id VARCHAR(255) UNIQUE NOT NULL, | ||
timeout DATETIME NOT NULL, | ||
INDEX (timeout), | ||
INDEX (saga_id) | ||
)` | ||
|
||
return &migrator.Migration{ | ||
Name: "create timeout table", | ||
Func: func(tx *sql.Tx) error { | ||
if _, err := tx.Exec(createTableQuery); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
//EnsureSchema implements Grabbit's migrations strategy | ||
func EnsureSchema(db *sql.DB, svcName string) { | ||
migrationsTable := fmt.Sprintf("grabbitMigrations_%s", svcName) | ||
|
||
migrate, err := migrator.New(migrator.TableName(migrationsTable), migrator.Migrations( | ||
OutboxMigrations(svcName), | ||
SagaStoreTableMigration(svcName), | ||
TimoutTableMigration(svcName), | ||
)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
err = migrate.Migrate(db) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
Oops, something went wrong.