-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Upgrade Details] For critical state transitions, fsync upgrade marke…
…r file (#3836) * Fix bug where markerFilePath was not being used * Fsync marker file write for critical upgrade transitions * Add unit test
- Loading branch information
1 parent
272c8e4
commit d31ed5b
Showing
7 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
internal/pkg/agent/application/upgrade/marker_access_common.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package upgrade | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func writeMarkerFileCommon(markerFile string, markerBytes []byte, shouldFsync bool) error { | ||
f, err := os.OpenFile(markerFile, os.O_WRONLY|os.O_CREATE, 0600) | ||
if err != nil { | ||
return fmt.Errorf("failed to open upgrade marker file for writing: %w", err) | ||
} | ||
defer f.Close() | ||
|
||
if _, err := f.Write(markerBytes); err != nil { | ||
return fmt.Errorf("failed to write upgrade marker file: %w", err) | ||
} | ||
|
||
if !shouldFsync { | ||
return nil | ||
} | ||
|
||
if err := f.Sync(); err != nil { | ||
return fmt.Errorf("failed to sync upgrade marker file to disk: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
internal/pkg/agent/application/upgrade/marker_access_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package upgrade | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWriteMarkerFile(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
markerFile := filepath.Join(tmpDir, markerFilename) | ||
|
||
markerBytes := []byte("foo bar") | ||
err := writeMarkerFile(markerFile, markerBytes, true) | ||
require.NoError(t, err) | ||
|
||
data, err := os.ReadFile(markerFile) | ||
require.NoError(t, err) | ||
require.Equal(t, markerBytes, data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters