Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix windows compile error for directio pkg #275

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions directio/proxy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 PingCAP, Inc.
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,11 +16,7 @@
package directio

import (
"errors"
"os"

"github.com/ncw/directio"
"golang.org/x/sys/unix"
)

const (
Expand All @@ -33,14 +29,3 @@ const (
// 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
}
36 changes: 36 additions & 0 deletions directio/proxy_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2023 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"
)

// 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
}
24 changes: 24 additions & 0 deletions directio/proxy_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 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.

//go:build !linux

package directio

import (
"github.com/ncw/directio"
)

// TODO: check the errors and fallback for the systems besides linux
var OpenFile = directio.OpenFile