Why am i getting DurabilityImpossible everytime i execute a transaction

Here is the error

{
    "error": "transaction failed | query error |",
    "query_error": {
        "statement": "COMMIT",
        "errors": [
            {
                "code": 17007,
                "message": "Commit Transaction statement error"
            }
        ],
        "error_text": [
            {
                "cause": {
                    "cause": {
                        "bucket": "internal-portal",
                        "collection": "_default",
                        "document_key": "_txn:atr-261-#23b",
                        "error_description": "Durability requirements are impossible to achieve",
                        "error_name": "DurabilityImpossible",
                        "last_connection_id": "22b040510f68d3f4/031a412a467ac02e",
                        "last_dispatched_from": "127.0.0.1:3526",
                        "last_dispatched_to": "127.0.0.1:11210",
                        "msg": "durability impossible",
                        "opaque": 4404,
                        "scope": "_default",
                        "status_code": 161
                    },
                    "raise": "failed",
                    "retry": false,
                    "rollback": false
                },
                "code": 17007,
                "msg": "Commit Transaction statement error"
            }
        ],
        "http_status_code": 200
    }
}

And here is the golang code to execute it

bucket := r.db.Bucket
	userScope := r.db.UserScope
	cluster := r.db.Cluster
	scope := bucket.Scope(userScope)
	collection := scope.Collection("portfolio")
	_, err := cluster.Transactions().Run(func(ctx *gocb.TransactionAttemptContext) error {

		// delete array item
		query := "UPDATE portfolio SET " + fieldName + " = ARRAY v FOR v IN " + fieldName + " WHEN v.id != $fieldItemID END WHERE META().id = $userID;"
		params := make(map[string]interface{})
		params["fieldItemID"] = fieldItemID
		params["userID"] = userID

		_, err := ctx.Query(query, &gocb.TransactionQueryOptions{NamedParameters: params, Scope: scope})
		if err != nil {
			return err
		}

		// Check whether array is empty or not
		row, err := ctx.Get(collection, userID)
		if err != nil {
			return err
		}

		var portfolio models.Portfolio
		err = row.Content(&portfolio)
		if err != nil {
			return err
		}

	  fieldLength := 0
		switch fieldName {
			case "achievements":
					fieldLength = len(portfolio.Achievements)	
			case "certificates":
					fieldLength = len(portfolio.Certificates)			
			case "educations":
					fieldLength = len(portfolio.Educations)		
			case "experiences":
					fieldLength = len(portfolio.Experiences)
			case "projects":
					fieldLength = len(portfolio.Projects)		
			case "skills":
					fieldLength = len(portfolio.Skills)
		}

		// delete the field if array is empty
		if fieldLength == 0 {
			query := "UPDATE portfolio UNSET " + fieldName + " WHERE META().id = $userID;"
			params := make(map[string]interface{})
			params["userID"] = userID

			_, err := ctx.Query(query, &gocb.TransactionQueryOptions{NamedParameters: params, Scope: scope})
			if err != nil {
				return err
			}
		}

		return nil
	}, nil)

	if err != nil {
		return err
	}

	return nil

see Transactions DurabilityImpossibleException docs clarification

1 Like

Yes this is called out at the top of the Go transactions documentation as it’s a commonly hit issue during local development. See the “Single Node Cluster” section.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.