amitdpawar commented on code in PR #2777: URL: https://github.com/apache/cassandra/pull/2777#discussion_r1362059382
########## src/java/org/apache/cassandra/db/commitlog/DirectIOSegment.java: ########## @@ -0,0 +1,163 @@ +/* + * 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.cassandra.db.commitlog; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.file.Files; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.io.FSWriteError; +import org.apache.cassandra.io.util.FileUtils; + +/* + * Direct-IO segment. Allocates ByteBuffer using ByteBuffer.allocateDirect and align + * ByteBuffer.position, ByteBuffer.limit and FileChannel.position to page size (4K). + * Java-11 forces minimum page size to be written to disk with Direct-IO. + */ +public class DirectIOSegment extends CommitLogSegment +{ + ByteBuffer original; + static int minimumAllowedAlign; + + // Needed to track number of bytes written to disk in multiple of page size. + int lastWritten = 0; + + /** + * Constructs a new segment file. + * + * @param commitLog the commit log it will be used with. + */ + DirectIOSegment(CommitLog commitLog, AbstractCommitLogSegmentManager manager) + { + super(commitLog, manager); + + // mark the initial sync marker as uninitialised + int firstSync = buffer.position(); + buffer.putInt(firstSync + 0, 0); + buffer.putInt(firstSync + 4, 0); + + // Testing shows writing initial bytes takes some time. During peak load, it helps + // lot and Syncer thread can actually do flush activity. Making this initial + // slow operation to be executed by Allocator thread here. + int oldLastSyncedOffset = lastSyncedOffset; + // 8 bytes are written above. + lastSyncedOffset = 8; + flush(0, lastSyncedOffset); + lastSyncedOffset = oldLastSyncedOffset; + } + + ByteBuffer createBuffer(CommitLog commitLog) + { + if (minimumAllowedAlign == 0) + { + try + { + minimumAllowedAlign = (int)Files.getFileStore(logFile.toPath()).getBlockSize(); Review Comment: getBlockSize() returns long but variables used for flush operation are defined in int. These variables are "lastSyncedOffset", "startMarker" and "nextMarker". -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

