forked from dgraph-io/badger
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
open with directio at best effort (#274)
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
- Loading branch information
Showing
7 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2015 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// directio is a proxy package for github.com/pingcap/badger/directio | ||
package directio | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/ncw/directio" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
const ( | ||
// AlignSize is the size to align the buffer to | ||
AlignSize = directio.AlignSize | ||
// BlockSize is the minimum block size | ||
BlockSize = directio.BlockSize | ||
) | ||
|
||
// AlignedBlock returns []byte of size BlockSize aligned to a multiple | ||
// of AlignSize in memory (must be power of two) | ||
var AlignedBlock = directio.AlignedBlock | ||
|
||
// OpenFile tries to open file in directio mode. If the file system doesn't support directio, | ||
// it will fallback to open the file directly (without O_DIRECT) | ||
func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { | ||
file, err := directio.OpenFile(name, flag, perm) | ||
if errors.Is(err, unix.EINVAL) { | ||
return os.OpenFile(name, flag, perm) | ||
} | ||
|
||
return file, err | ||
} |
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