Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2539,4 +2539,9 @@ default BalanceResponse balanceRSGroup(String groupName) throws IOException {
*/
List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType, ServerType serverType,
int limit, Map<String, Object> filterParams) throws IOException;

/**
* Flush master local region
*/
void flushMasterStore() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1078,4 +1078,9 @@ public List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType,
ServerType serverType, int limit, Map<String, Object> filterParams) throws IOException {
return get(admin.getLogEntries(serverNames, logType, serverType, limit, filterParams));
}

@Override
public void flushMasterStore() throws IOException {
get(admin.flushMasterStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1785,4 +1785,9 @@ default CompletableFuture<BalanceResponse> balanceRSGroup(String groupName) {
*/
CompletableFuture<List<LogEntry>> getLogEntries(Set<ServerName> serverNames, String logType,
ServerType serverType, int limit, Map<String, Object> filterParams);

/**
* Flush master local region
*/
CompletableFuture<Void> flushMasterStore();
}
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,9 @@ public CompletableFuture<List<LogEntry>> getLogEntries(Set<ServerName> serverNam
String logType, ServerType serverType, int limit, Map<String, Object> filterParams) {
return wrap(rawAdmin.getLogEntries(serverNames, logType, serverType, limit, filterParams));
}

@Override
public CompletableFuture<Void> flushMasterStore() {
return wrap(rawAdmin.flushMasterStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableTableResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushMasterStoreRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushMasterStoreResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsRequest;
Expand Down Expand Up @@ -4280,4 +4282,14 @@ public CompletableFuture<List<LogEntry>> getLogEntries(Set<ServerName> serverNam
return CompletableFuture.completedFuture(Collections.emptyList());
}
}

@Override
public CompletableFuture<Void> flushMasterStore() {
FlushMasterStoreRequest.Builder request = FlushMasterStoreRequest.newBuilder();
return this.<Void> newMasterCaller()
.action(((controller, stub) -> this.<FlushMasterStoreRequest, FlushMasterStoreResponse,
Void> call(controller, stub, request.build(),
(s, c, req, done) -> s.flushMasterStore(c, req, done), resp -> null)))
.call();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ message ModifyColumnStoreFileTrackerResponse {
optional uint64 proc_id = 1;
}

message FlushMasterStoreRequest {}
message FlushMasterStoreResponse {}

service MasterService {
/** Used by the client to get the number of regions that have received the updated schema */
rpc GetSchemaAlterStatus(GetSchemaAlterStatusRequest)
Expand Down Expand Up @@ -1197,6 +1200,9 @@ service MasterService {

rpc ModifyColumnStoreFileTracker(ModifyColumnStoreFileTrackerRequest)
returns(ModifyColumnStoreFileTrackerResponse);

rpc FlushMasterStore(FlushMasterStoreRequest)
returns(FlushMasterStoreResponse);
}

// HBCK Service definitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ public class HMaster extends HBaseServerBase<MasterRpcServices> implements Maste
public static final String WARMUP_BEFORE_MOVE = "hbase.master.warmup.before.move";
private static final boolean DEFAULT_WARMUP_BEFORE_MOVE = true;

// Only for testing
private boolean isLocalRegionFlushed = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to not adding a flag which is only used to verify test result? I think you can add a CP method for the flushMasterRegion call, and use attach a CP to verify that whether the master is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does CP here mean coprocessor? Is there a similar implementation example? sir @Apache9


/**
* Initializes the HMaster. The steps are as follows:
* <p>
Expand Down Expand Up @@ -4207,6 +4210,19 @@ public List<HRegionLocation> getMetaLocations() {
return metaRegionLocationCache.getMetaRegionLocations();
}

@Override
public void flushMasterStore() throws IOException {
LOG.info("Force flush master local region.");
masterRegion.flush(true);
isLocalRegionFlushed = true;
}

@RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*")
public boolean isLocalRegionFlushed() {
return isLocalRegionFlushed;
}

public Collection<ServerName> getLiveRegionServers() {
return regionServerTracker.getRegionServers();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushMasterStoreRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushMasterStoreResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsRequest;
Expand Down Expand Up @@ -3468,4 +3470,16 @@ public ReplicateWALEntryResponse replicateToReplica(RpcController controller,
ReplicateWALEntryRequest request) throws ServiceException {
throw new ServiceException(new DoNotRetryIOException("Unsupported method on master"));
}

@Override
public FlushMasterStoreResponse flushMasterStore(RpcController controller,
FlushMasterStoreRequest request) throws ServiceException {
rpcPreCheck("flushMasterStore");
try {
server.flushMasterStore();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
return FlushMasterStoreResponse.newBuilder().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,9 @@ boolean normalizeRegions(final NormalizeTableFilterParams ntfp, final boolean is
* We need to get this in MTP to tell the syncer the new meta replica count.
*/
MetaLocationSyncer getMetaLocationSyncer();

/**
* Flush master local region
*/
void flushMasterStore() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ public RegionScanner getRegionScanner(Scan scan) throws IOException {
return region.getScanner(scan);
}

@RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*")
public FlushResult flush(boolean force) throws IOException {
flusherAndCompactor.resetChangesAfterLastFlush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add a line, but where do we reset this in tha past? We do not need to remove the original one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, the flush method is only called by test cases, reset is not called in this method, and there is no reset logic in the relevant test cases: TestMasterRegionWALCleaner/TestMasterRegionOnTwoFileSystems and so on.

Can you help me make sure we don't need reset logic either?

Copy link
Contributor Author

@2005hithlj 2005hithlj Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add a line, but where do we reset this in tha past? We do not need to remove the original one?

Do you mean the following changes are OK?

public FlushResult flush(boolean force) throws IOException {
flusherAndCompactor.resetChangesAfterLastFlush();
return region.flush(force);
}

@Apache9 sir.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we have reset logic in MasterRegionFlusherAndCompactor, before calling this flush method. Now we move the reset logic into this method, then we should remove the reset logic in MasterRegionFlusherAndCompactor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! I have understood what you mean.
I have a new commit again, could you take a look when you have time?
@Apache9 sir.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to record the lastFlushTime here?

return region.flush(force);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void flushLoop() {
flushLock.unlock();
}
assert flushRequest;
changesAfterLastFlush.set(0);
resetChangesAfterLastFlush();
try {
region.flush(true);
lastFlushTime = EnvironmentEdgeManager.currentTime();
Expand Down Expand Up @@ -263,6 +263,10 @@ void requestFlush() {
}
}

void resetChangesAfterLastFlush() {
changesAfterLastFlush.set(0);
}

@Override
public void close() {
closed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ public MetaLocationSyncer getMetaLocationSyncer() {
return null;
}

@Override
public void flushMasterStore() {
}

@Override
public long modifyTableStoreFileTracker(TableName tableName, String dstSFT, long nonceGroup,
long nonce) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
Expand Down Expand Up @@ -148,6 +149,15 @@ public void testPeriodicalFlush() throws InterruptedException {
assertEquals(1, flushCalled.get());
Thread.sleep(1000);
assertEquals(2, flushCalled.get());
}

@Test
public void testForceFlush() throws Exception {
// Test for HBASE-27028
HBaseTestingUtil htu = new HBaseTestingUtil();
htu.startMiniCluster(1);
htu.getConnection().getAdmin().flushMasterStore();
assertTrue(htu.getMiniHBaseCluster().getMaster().isLocalRegionFlushed());
htu.shutdownMiniCluster();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,9 @@ public Future<Void> modifyTableStoreFileTrackerAsync(TableName tableName, String
throws IOException {
return admin.modifyTableStoreFileTrackerAsync(tableName, dstSFT);
}

@Override
public void flushMasterStore() throws IOException {
admin.flushMasterStore();
}
}
8 changes: 7 additions & 1 deletion hbase-shell/src/main/ruby/hbase/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1868,11 +1868,17 @@ def modify_table_sft(tableName, sft)
@admin.modifyTableStoreFileTracker(tableName, sft)
end

#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------
# Change table column family's sft
def modify_table_family_sft(tableName, family_bytes, sft)
@admin.modifyColumnFamilyStoreFileTracker(tableName, family_bytes, sft)
end

#----------------------------------------------------------------------------------------------
# Flush master local region
def flush_master_store()
@admin.flushMasterStore()
end
end
# rubocop:enable Metrics/ClassLength
end
1 change: 1 addition & 0 deletions hbase-shell/src/main/ruby/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ def self.exception_handler(hide_traceback)
compact
compaction_switch
flush
flush_master_store
get_balancer_decisions
get_balancer_rejections
get_slowlog_responses
Expand Down
37 changes: 37 additions & 0 deletions hbase-shell/src/main/ruby/shell/commands/flush_master_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
#
# 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.
#

module Shell
module Commands
class FlushMasterStore < Command
def help
<<-EOF
Flush master local region.
For example:

hbase> flush_master_store
EOF
end

def command()
admin.flush_master_store()
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -1309,4 +1309,9 @@ public Future<Void> modifyTableStoreFileTrackerAsync(TableName tableName, String
throw new NotImplementedException(
"modifyTableStoreFileTrackerAsync not supported in ThriftAdmin");
}

@Override
public void flushMasterStore() throws IOException {
throw new NotImplementedException("flushMasterStore not supported in ThriftAdmin");
}
}