Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1454

Make Session interface implementable by external packages

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Hi,

      I am using the Session interface to implement transactions. Now, there are several fallback logic in it, which aborts the transaction. Now, in order to simulate those failure behaviors, I was trying to have a mock implementation of the Session interface, but as there is an unexported function session() which inhibits it, the last one.

      https://github.com/mongodb/mongo-go-driver/blob/master/mongo/session.go#L92

      // Session is the interface that represents a sequential set of operations executed.
      // Instances of this interface can be used to use transactions against the server
      // and to enable causally consistent behavior for applications.
      type Session interface {
         EndSession(context.Context)
         WithTransaction(ctx context.Context, fn func(sessCtx SessionContext) (interface{}, error), opts ...*options.TransactionOptions) (interface{}, error)
         StartTransaction(...*options.TransactionOptions) error
         AbortTransaction(context.Context) error
         CommitTransaction(context.Context) error
         ClusterTime() bson.Raw
         AdvanceClusterTime(bson.Raw) error
         OperationTime() *primitive.Timestamp
         AdvanceOperationTime(*primitive.Timestamp) error
         Client() *Client
         session()
      }
      

      I strongly believe there must be a design decision for keeping it that way, but can you just tell me a little bit about it, or maybe point in the right direction. Also, is it at all possible to make it an exported function, so the users of this package can have their own custom implementation of the Session interface? If it is indeed possible, I would love it if I can be of any help in this change.

      Also, can you suggest me some ways in which I can simulate the failure behavior of transaction,  I would be really thankful.

       

            Assignee:
            isabella.siu@mongodb.com Isabella Siu (Inactive)
            Reporter:
            kaustubhmallik@gmail.com Kaustubh Mallik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: