mirror of https://github.com/portainer/portainer
fix(database): fix a data race around the bucket sequences EE-4332 (#7738)
parent
90a0e6fe35
commit
e9384a6987
|
@ -30,7 +30,6 @@ type Connection interface {
|
||||||
CreateObject(bucketName string, fn func(uint64) (int, interface{})) error
|
CreateObject(bucketName string, fn func(uint64) (int, interface{})) error
|
||||||
CreateObjectWithId(bucketName string, id int, obj interface{}) error
|
CreateObjectWithId(bucketName string, id int, obj interface{}) error
|
||||||
CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error
|
CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error
|
||||||
CreateObjectWithSetSequence(bucketName string, id int, obj interface{}) error
|
|
||||||
GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error
|
GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error
|
||||||
GetAllWithJsoniter(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error
|
GetAllWithJsoniter(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error
|
||||||
ConvertToKey(v int) []byte
|
ConvertToKey(v int) []byte
|
||||||
|
|
|
@ -325,27 +325,6 @@ func (connection *DbConnection) CreateObjectWithStringId(bucketName string, id [
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateObjectWithSetSequence creates a new object in the bucket, using the specified id, and sets the bucket sequence
|
|
||||||
// avoid this :)
|
|
||||||
func (connection *DbConnection) CreateObjectWithSetSequence(bucketName string, id int, obj interface{}) error {
|
|
||||||
return connection.Batch(func(tx *bolt.Tx) error {
|
|
||||||
bucket := tx.Bucket([]byte(bucketName))
|
|
||||||
|
|
||||||
// We manually manage sequences for schedules
|
|
||||||
err := bucket.SetSequence(uint64(id))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := connection.MarshalObject(obj)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bucket.Put(connection.ConvertToKey(id), data)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (connection *DbConnection) GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error {
|
func (connection *DbConnection) GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error {
|
||||||
err := connection.View(func(tx *bolt.Tx) error {
|
err := connection.View(func(tx *bolt.Tx) error {
|
||||||
bucket := tx.Bucket([]byte(bucketName))
|
bucket := tx.Bucket([]byte(bucketName))
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (service *Service) Endpoints() ([]portainer.Endpoint, error) {
|
||||||
|
|
||||||
// CreateEndpoint assign an ID to a new environment(endpoint) and saves it.
|
// CreateEndpoint assign an ID to a new environment(endpoint) and saves it.
|
||||||
func (service *Service) Create(endpoint *portainer.Endpoint) error {
|
func (service *Service) Create(endpoint *portainer.Endpoint) error {
|
||||||
return service.connection.CreateObjectWithSetSequence(BucketName, int(endpoint.ID), endpoint)
|
return service.connection.CreateObjectWithId(BucketName, int(endpoint.ID), endpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNextIdentifier returns the next identifier for an environment(endpoint).
|
// GetNextIdentifier returns the next identifier for an environment(endpoint).
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (service *Service) SchedulesByJobType(jobType portainer.JobType) ([]portain
|
||||||
|
|
||||||
// Create assign an ID to a new schedule and saves it.
|
// Create assign an ID to a new schedule and saves it.
|
||||||
func (service *Service) CreateSchedule(schedule *portainer.Schedule) error {
|
func (service *Service) CreateSchedule(schedule *portainer.Schedule) error {
|
||||||
return service.connection.CreateObjectWithSetSequence(BucketName, int(schedule.ID), schedule)
|
return service.connection.CreateObjectWithId(BucketName, int(schedule.ID), schedule)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNextIdentifier returns the next identifier for a schedule.
|
// GetNextIdentifier returns the next identifier for a schedule.
|
||||||
|
|
|
@ -134,7 +134,7 @@ func (service *Service) GetNextIdentifier() int {
|
||||||
|
|
||||||
// CreateStack creates a new stack.
|
// CreateStack creates a new stack.
|
||||||
func (service *Service) Create(stack *portainer.Stack) error {
|
func (service *Service) Create(stack *portainer.Stack) error {
|
||||||
return service.connection.CreateObjectWithSetSequence(BucketName, int(stack.ID), stack)
|
return service.connection.CreateObjectWithId(BucketName, int(stack.ID), stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStack updates a stack.
|
// UpdateStack updates a stack.
|
||||||
|
|
Loading…
Reference in New Issue