This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
forked from apache/bookkeeper
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract the FileChanne in the JournalChannel
**Motivation** Make the FileChannel in the JournalChannel can use different implement. We found we can use [pmemstore](https://github.com/4paradigm/pmemstore) as the JournalChannel read from. So abstract the FileChannel in the JournnalChannel to make us can have different implementation.
- Loading branch information
Showing
6 changed files
with
203 additions
and
16 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieFileChannel.java
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,53 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.bookkeeper.bookie; | ||
|
||
import java.io.File; | ||
import java.io.FileDescriptor; | ||
import java.io.IOException; | ||
import java.nio.channels.FileChannel; | ||
|
||
/** | ||
* A FileChannel for the JournalChannel read and write, we can use this interface to extend the FileChannel | ||
* which we use in the JournalChannel. | ||
*/ | ||
interface BookieFileChannel { | ||
|
||
/** | ||
* An interface for get the FileChannel from the provider. | ||
* @return | ||
*/ | ||
FileChannel getFileChannel(); | ||
|
||
/** | ||
* Check the given file if exists. | ||
* | ||
* @param file | ||
* @return | ||
*/ | ||
boolean fileExists(File file); | ||
|
||
/** | ||
* Get the file descriptor of the opened file. | ||
* | ||
* @return | ||
* @throws IOException | ||
*/ | ||
FileDescriptor getFD() throws IOException; | ||
} |
61 changes: 61 additions & 0 deletions
61
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultFileChannelProvider.java
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,61 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.bookkeeper.bookie; | ||
|
||
import org.apache.bookkeeper.conf.ServerConfiguration; | ||
|
||
import java.io.File; | ||
import java.io.FileDescriptor; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import java.nio.channels.FileChannel; | ||
|
||
public class DefaultFileChannelProvider implements FileChannelProvider{ | ||
@Override | ||
public BookieFileChannel open(File file, ServerConfiguration configuration) throws IOException { | ||
return new DefaultFileChannel(file, configuration); | ||
} | ||
|
||
static class DefaultFileChannel implements BookieFileChannel { | ||
private final File file; | ||
private final RandomAccessFile randomAccessFile; | ||
private final ServerConfiguration configuration; | ||
|
||
DefaultFileChannel(File file, ServerConfiguration serverConfiguration) throws IOException { | ||
this.file = file; | ||
this.randomAccessFile = new RandomAccessFile(file, "rw"); | ||
this.configuration = serverConfiguration; | ||
} | ||
|
||
@Override | ||
public FileChannel getFileChannel() { | ||
return randomAccessFile.getChannel(); | ||
} | ||
|
||
@Override | ||
public boolean fileExists(File file) { | ||
return file.exists(); | ||
} | ||
|
||
@Override | ||
public FileDescriptor getFD() throws IOException { | ||
return randomAccessFile.getFD(); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/FileChannelProvider.java
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,49 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.bookkeeper.bookie; | ||
|
||
import org.apache.bookkeeper.conf.ServerConfiguration; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* An interface of the FileChannelProvider. | ||
*/ | ||
public interface FileChannelProvider { | ||
static FileChannelProvider newProvider(String providerClassName) throws IOException { | ||
try { | ||
Class<?> providerClass = Class.forName(providerClassName); | ||
Object obj = providerClass.newInstance(); | ||
return (FileChannelProvider) obj; | ||
} catch (Exception e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Get the BookieFileChannel with the given file and configuration. | ||
* | ||
* @param file | ||
* @param configuration | ||
* @return | ||
* @throws IOException | ||
*/ | ||
BookieFileChannel open(File file, ServerConfiguration configuration) throws IOException; | ||
} |
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