-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-24822 Add a command to support archive the earliest log file ma… #2202
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,12 @@ message RollWALWriterResponse { | |
repeated bytes region_to_flush = 1; | ||
} | ||
|
||
message ArchiveWALRequest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be renamed to go with the updated method name ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix later. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought again, it should be a common name if we want to improve it in future, such as archive a specify log file, archive all log files, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it make sense, i will remove the "earliest" from method name also. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ArchiveWALResponse should contain the status of archival (including error). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked the existing api in Admin.java, such as flushRegion, compactRegion, seems currently we dont use status, if there is something wrong at server side, we notice client by throw ServiceException. |
||
} | ||
|
||
message ArchiveWALResponse { | ||
} | ||
|
||
message StopServerRequest { | ||
required string reason = 1; | ||
} | ||
|
@@ -351,6 +357,9 @@ service AdminService { | |
rpc RollWALWriter(RollWALWriterRequest) | ||
returns(RollWALWriterResponse); | ||
|
||
rpc ArchiveWAL(ArchiveWALRequest) | ||
returns(ArchiveWALResponse); | ||
|
||
rpc GetServerInfo(GetServerInfoRequest) | ||
returns(GetServerInfoResponse); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,14 +57,17 @@ | |
import org.apache.hadoop.hbase.HBaseConfiguration; | ||
import org.apache.hadoop.hbase.HConstants; | ||
import org.apache.hadoop.hbase.PrivateCellUtil; | ||
import org.apache.hadoop.hbase.RegionException; | ||
import org.apache.hadoop.hbase.client.RegionInfo; | ||
import org.apache.hadoop.hbase.exceptions.TimeoutIOException; | ||
import org.apache.hadoop.hbase.io.util.MemorySizeUtil; | ||
import org.apache.hadoop.hbase.ipc.RpcServer; | ||
import org.apache.hadoop.hbase.ipc.ServerCall; | ||
import org.apache.hadoop.hbase.log.HBaseMarkers; | ||
import org.apache.hadoop.hbase.regionserver.FlushLifeCycleTracker; | ||
import org.apache.hadoop.hbase.regionserver.HRegion; | ||
import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl; | ||
import org.apache.hadoop.hbase.regionserver.RegionServerServices; | ||
import org.apache.hadoop.hbase.trace.TraceUtil; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
|
@@ -718,7 +721,7 @@ private void cleanOldLogs() throws IOException { | |
if (logsToArchive != null) { | ||
for (Pair<Path, Long> logAndSize : logsToArchive) { | ||
this.totalLogSize.addAndGet(-logAndSize.getSecond()); | ||
archiveLogFile(logAndSize.getFirst()); | ||
moveLogFileToArchiveDir(logAndSize.getFirst()); | ||
this.walFile2Props.remove(logAndSize.getFirst()); | ||
} | ||
} | ||
|
@@ -732,7 +735,7 @@ public static Path getWALArchivePath(Path archiveDir, Path p) { | |
return new Path(archiveDir, p.getName()); | ||
} | ||
|
||
private void archiveLogFile(final Path p) throws IOException { | ||
private void moveLogFileToArchiveDir(final Path p) throws IOException { | ||
Path newPath = getWALArchivePath(this.walArchiveDir, p); | ||
// Tell our listeners that a log is going to be archived. | ||
if (!this.listeners.isEmpty()) { | ||
|
@@ -872,6 +875,33 @@ public Map<byte[], List<byte[]>> rollWriter(boolean force) throws IOException { | |
} | ||
} | ||
|
||
public void archive(RegionServerServices services) throws IOException{ | ||
if (getNumRolledLogFiles() < 1) { | ||
return; | ||
} | ||
// get the earliest log of this WAL instance | ||
Map.Entry<Path, WalProps> firstWALEntry = this.walFile2Props.firstEntry(); | ||
// flush regions if necessary | ||
Map<byte[], List<byte[]>> regions = | ||
this.sequenceIdAccounting.findLower(firstWALEntry.getValue().encodedName2HighestSequenceId); | ||
if (regions != null) { | ||
for (Map.Entry<byte[], List<byte[]>> entry : regions.entrySet()) { | ||
String encodedRegionName = Bytes.toString(entry.getKey()); | ||
HRegion r = (HRegion) services.getRegion(encodedRegionName); | ||
if (r == null) { | ||
throw new RegionException("Failed to flush of " + encodedRegionName + | ||
" when archive manually, because it is not online on rs"); | ||
} | ||
r.flushcache(entry.getValue(), false, FlushLifeCycleTracker.DUMMY); | ||
} | ||
} | ||
|
||
// move the log file to archive dir | ||
moveLogFileToArchiveDir(firstWALEntry.getKey()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if IOException is thrown from this call ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, the move action should be called first. |
||
this.totalLogSize.addAndGet(-firstWALEntry.getValue().logSize); | ||
this.walFile2Props.remove(firstWALEntry.getKey()); | ||
} | ||
|
||
// public only until class moves to o.a.h.h.wal | ||
/** @return the size of log files in use */ | ||
public long getLogFileSize() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should method name reflect that the earliest log is archived ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will fix later.
Thanks.