Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record will not be replicated to other clusters with returning clause #141

Closed
rockmenjack opened this issue Jun 1, 2021 · 2 comments
Closed
Labels
Bug Confirmed to be a bug

Comments

@rockmenjack
Copy link

rockmenjack commented Jun 1, 2021

refer: https://sqlite.org/lang_returning.html

can be easily reproduced in master branch with below test case:
prerequisite: go-dqlite linked against sqlite3 >= v3.35.0

func TestDqliteBasic(t *testing.T) {
	var (
		file1 = "/db1"
		file2 = "/db2"
		file3 = "/db3"

		url1 = "127.0.0.1:2379"
		url2 = "127.0.0.1:2380"
		url3 = "127.0.0.1:2381"

		tempDir string
		err     error

		ctx = context.Background()

		failOnError = func(err error) {
			t.Helper()
			if err != nil {
				t.Fatal(err)
			}
		}
		
	)

	tempDir, err = ioutil.TempDir("", "dqlite-test-*")
	failOnError(err)
	defer func() {
		if t.Failed() {
			t.Logf("db data kept in %s =====\n", tempDir)
		} else {
			os.RemoveAll(tempDir)
		}
	}()

	err = os.MkdirAll(tempDir+file1, 0755)
	failOnError(err)

	err = os.MkdirAll(tempDir+file2, 0755)
	failOnError(err)

	err = os.MkdirAll(tempDir+file3, 0755)
	failOnError(err)

	app1, err := app.New(tempDir+file1, app.WithAddress(url1))
	failOnError(err)
	defer app1.Close()

	db1, err := app1.Open(ctx, "main")
	failOnError(err)


	app2, err := app.New(tempDir+file2, app.WithAddress(url2), app.WithCluster([]string{url2, url1}))
	failOnError(err)
	defer app2.Close()

	db2, err := app1.Open(ctx, "main")
	failOnError(err)


	app3, err := app.New(tempDir+file3, app.WithAddress(url3), app.WithCluster([]string{url2, url1, url3}))
	failOnError(err)
	defer app3.Close()

	db3, err := app1.Open(ctx, "main")
	failOnError(err)

	_, err = db1.Exec("CREATE TABLE my_table (n INT)")
	failOnError(err)

	var d2 int
	// row := db2.QueryRow("INSERT INTO my_table (n) VALUES (10)")   <--  everything works fine without RETURNING
	row := db2.QueryRow("INSERT INTO my_table (n) VALUES (10) RETURNING n")
	err = row.Scan(&d2)
	failOnError(err)
	t.Logf("got from db2: %d", d2)

	row = db3.QueryRow(`SELECT * FROM my_table`)
	var d3 int
	err = row.Scan(&d3)
	failOnError(err)

	t.Logf("got from db3: %d", d3)
}
@MathieuBordere MathieuBordere added the Bug Confirmed to be a bug label Jun 1, 2021
@MathieuBordere
Copy link

Thank you for your report and the reproduction scenario, we'll investigate.

@MathieuBordere
Copy link

I'll track this in #192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed to be a bug
Projects
None yet
Development

No branches or pull requests

2 participants