package main func main() { c := make(chan int, 1) for range 3 { select { default: println(1) case <-c: println(2) case c <- 1: println(3) } } }
Golang
```go func fail() { panic("Fail!") } func main() { fmt.Println("Start!") var wg sync.WaitGroup wg.Add(1) go func() { defer func() { if e := recover(); e != nil { fmt.Println(e) } }() fail() wg.Done() }() wg.Wait() fmt.Println("Finish!") } ```
Why did you choose Elasticsearch? What other options were there? Did you choose something or was ELK already there?
Do you have any questions about the projects or working conditions?
You say that you used Elasticsearch to create a system for quick transaction searches. What is it, how many transactions does it handle, and what are the benefits?
func fetch(ctx context.Context, u User) (string, error) { // do something over the network time.Sleep(time.Millisecond * 10) // simulate delay return u.Name, nil //return "", errors.New("some error") } func Do(ctx context.Context, users []User) (map[string]int64, error) { var mu sync.Mutex var wg sync.WaitGroup ch := make(chan error, len(users)) names := make(map[string]int64, 0) ctxWithCancel, cancel := context.WithCancel(ctx) wg.Add(len(users)) for _, u := range users { go func() { defer wg.Done() select { case name, err := fetch(ctx, u): if err != nil { ch <- err return } mu.Lock() names[name] = names[name] + 1 mu.Unlock() case <-ctxWithCancel.Err: } }() }
In the end, which solutions did you choose from? ClickHouse, ELK, and what was the third one?
Where are you currently working?
After implementing Elasticsearch, was there any product feedback from users or technical support?
What makes a system high-load? Based on your expertise.
Do you have a military ID?
From what amount do you consider an offer?
package main import ( "fmt" ) func main() { c := make(chan string, 1) go fmt.Println(<-c) c <- "Hello World!" fmt.Println("Exit!") } fatal error: all goroutines are asleep - deadlock! goroutine 1 [chan receive]: main.main() /tmp/sandbox[phone]/prog.go:10 +0x3a Program exited: status 2.
package main func main() { c := make(chan int) for range 3 { select { default: println(1) case <-c: println(2) case c <- 1: println(3) } } }
package main import ( "fmt" ) func main() { c := make(chan string) go fmt.Println(<-c) c <- "Hello World!" fmt.Println("Exit!") }
What do services have to do with it, if we are talking about fault tolerance and have reduced it to replicas?
package main import ( "fmt" ) func main() { c := make(chan string) go fmt.Println(<-c) c <- "Hello World!" fmt.Println("Exit!") } fatal error: all goroutines are asleep - deadlock! goroutine 1 [chan receive]: main.main() /tmp/sandbox[phone]/prog.go:10 +0x3a Program exited: status 2.
```go var defaultTxOptions = &sql.TxOptions{} const defaultCurrency = "RUB" func CreateUserWithDefaultCurrency(ctx context.Context, db *sql.DB, email, passwordHash string) error { tx, err := db.BeginTx(ctx, defaultTxOptions) if err != nil { return err } defer func() { if err != nil{ tx.Rollback() } }() _, err = tx.Exec("INSERT INTO users (email, password) VALUES (?, ?)", email, passwordHash) if err != nil { return err } rows, err := tx.Query("SELECT id FROM users WHERE email = ?", email) if err != nil { return err } defer rows.Close() id := 0 for rows.Next() { err = rows.Scan(&id) if err != nil { return err } } _, err = tx.Exec("INSERT INTO balances (user_id, currency, current_balance) VALUES (?, ?, 0)", id, defaultCurrency) if err != nil { return err } return tx.Commit() } ```
Where do you currently reside?
func Do(ctx context.Context, users []User) (map[string]int64, error) { var mu sync.Mutex var wg sync.WaitGroup ch := make(chan error, len(users)) names := make(map[string]int64, 0) ctxWithCancel, cancel := context.WithCancel(ctx) wg.Add(len(users)) for _, u := range users { go func() { defer wg.Done() select { case name, err := fetch(ctx, u): if err != nil { ch <- err return } mu.Lock() names[name] = names[name] + 1 mu.Unlock() case <-ctxWithCancel.Err: } }() } return names, nil }