mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-25 10:40:02 +08:00
* Unify behavior of the uploaders - Changes the behavior of uploaders to allow uploading pending summaries. It also makes all uploaders consistently fail to overwrite existing recordings and final summaries. - Upgrades the gofakes3 library to support the If-None-Match headers. - Copies the MemBuffer utility from the enterprise code. * Fix a deadlock in gcsessions.Handler The deadlock occurred when the upload passed a certain number of parts, in which case the errors channel buffer got saturated and the object deletion goroutines started piling up, ultimately leading to locking the main loop that iterated through the object slice when the semaphore channel got its buffer filled up too. This deadlock prevented running the GCS uploader integration tests. * review * Another review round - Move the pending session downloading to the caller - Add a missing MemBuffer test - Tweaks to the memory uploader (required by the Enterprise change) * Build fix * review * Fix lint and integration tests * Delete the pending summaries when uploading final, use versioning on s3 * Some comments * license
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
// Teleport
|
|
// Copyright (C) 2025 Gravitational, Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package events
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
|
|
)
|
|
|
|
// MemBuffer is a in-memory byte buffer that implements both io.Writer and
|
|
// io.WriterAt interfaces.
|
|
type MemBuffer struct {
|
|
buf manager.WriteAtBuffer
|
|
// mu is a mutex to protect concurrent writes to the buffer. Even though the
|
|
// underlying buffer is thread-safe, we need to prevent a race condition in
|
|
// [MemBuffer.Write] between checking the length of the buffer and writing to
|
|
// it.
|
|
mu sync.Mutex
|
|
}
|
|
|
|
func (b *MemBuffer) Write(p []byte) (int, error) {
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
return b.buf.WriteAt(p, int64(len(b.buf.Bytes())))
|
|
}
|
|
|
|
func (b *MemBuffer) WriteAt(p []byte, pos int64) (int, error) {
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
return b.buf.WriteAt(p, pos)
|
|
}
|
|
|
|
// Bytes return the underlying byte slice.
|
|
func (b *MemBuffer) Bytes() []byte {
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
return b.buf.Bytes()
|
|
}
|