-
Notifications
You must be signed in to change notification settings - Fork 7
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
WIP: End transaction request/response #8
Conversation
Signed-off-by: Peter Verraedt <[email protected]>
(By the way, we run against mysql, not sure whether postgres would do the same) |
a9f5ec5
to
ca60ded
Compare
Since the endTransaction API has restricted access, we add the ModColRequest message and use it for a poor mans version of rollback. It is crafted such that the server will do nothing except a rollback of the empty transaction. Signed-off-by: Peter Verraedt <[email protected]>
We make sure connections retrieved from session.AcquireConnection have the most recent view on the database. Signed-off-by: Peter Verraedt <[email protected]>
ca60ded
to
8c53c58
Compare
Thank you for the commit. I'll test it with postgres db. It may take some time to review. |
FYI my test script. It prints pointers, it is the count of files that matters. import (
"fmt"
"math/rand"
"time"
"github.com/cyverse/go-irodsclient/irods/common"
"github.com/cyverse/go-irodsclient/irods/connection"
"github.com/cyverse/go-irodsclient/irods/fs"
"github.com/cyverse/go-irodsclient/irods/types"
)
func test() error {
conn1, _ := connection.NewIRODSConnection(...)
conn2, _ := connection.NewIRODSConnection(...)
printCol(conn1)
printCol(conn2)
rand.Seed(time.Now().Unix())
filename := fmt.Sprintf("/irods_zone/home/rods/test.%d", rand.Uint32())
fmt.Sprintf("%s\n", filename)
putInFile(conn1, filename)
printCol(conn1) // new file is seen
printCol(conn2) // new file is not seen
filename2 := fmt.Sprintf("/irods_zone/home/rods/test.%d", rand.Uint32())
fmt.Sprintf("%s\n", filename2)
//addMeta(conn2, "/icts_icts/home/rods")
putInFile(conn2, filename2)
printCol(conn1) // first new file is seen, second file not
printCol(conn2) // both new files are seen
fmt.Print(conn1.PoorMansRollback())
printCol(conn1) // both new files are seen
printCol(conn2) // both new files are seen
conn3, _ := z.AcquireConnection()
printCol(conn3) // both new files are seen
return nil
}
func printCol(conn *connection.IRODSConnection) {
coll, _ := fs.GetCollection(conn, "/irods_zone/home/rods")
obj, _ := fs.ListDataObjectsMasterReplica(conn, coll)
fmt.Printf("%v (%d)\n", obj, len(obj))
}
func putInFile(conn *connection.IRODSConnection, filename string) error {
handle, err := fs.OpenDataObjectWithOperation(conn, filename, "default", "w", common.OPER_TYPE_PUT_DATA_OBJ)
if err != nil {
return err
}
err = fs.WriteDataObject(conn, handle, []byte("hello\n"))
if err != nil {
return err
}
return fs.CloseDataObject(conn, handle)
}
func addMeta(conn *connection.IRODSConnection, dirname string) error {
return fs.AddCollectionMeta(conn, dirname, &types.IRODSMeta{
Name: "a",
Value: fmt.Sprintf("%d", rand.Int()),
})
} |
It seems that the issue doesn't occur with postgres db. But doing the rollback didn't harm to the postgres db. |
This has bitten me and and a couple of colleagues for a day or so.
One does not see this as long as only one connection from the pool is used.
We learned that
In this PR, I added the end transaction messages, and a Commit/Rollback function. Calling the Commit() function out of the blue is like doing nothing and still force a new database transaction to start and see the most recent changes in the database. This works however only for connections as rodsadmin.
For regular users, a dummy operation is enough. I added PoorMansCommit, but this should be cleaned up.