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

Improve the implementation of backup in HelixAccountService #1246

Merged
merged 6 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.helix.AccessOption;
import org.apache.helix.ZNRecord;
import org.apache.helix.store.HelixPropertyStore;
import org.apache.zookeeper.data.Stat;
justinlin-linkedin marked this conversation as resolved.
Show resolved Hide resolved
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -30,20 +31,20 @@ abstract class AccountMetadataStore {
private static final Logger logger = LoggerFactory.getLogger(AccountMetadataStore.class);

protected final AccountServiceMetrics accountServiceMetrics;
protected final LocalBackup backup;
protected final BackupFileManager backupFileManager;
protected final String znRecordPath;
private final HelixPropertyStore<ZNRecord> helixStore;

/** Create a new {@link AccountMetadataStore} instance for the subclasses.
* @param accountServiceMetrics The {@link AccountServiceMetrics}
* @param backup The {@link LocalBackup} to manage the backup files.
* @param backupFileManager The {@link BackupFileManager} to manage the backup files.
* @param helixStore The {@link HelixPropertyStore} to retrieve and update the {@link ZNRecord}.
* @param znRecordPath The {@link ZNRecord} path.
*/
AccountMetadataStore(AccountServiceMetrics accountServiceMetrics, LocalBackup backup,
AccountMetadataStore(AccountServiceMetrics accountServiceMetrics, BackupFileManager backupFileManager,
HelixPropertyStore<ZNRecord> helixStore, String znRecordPath) {
this.accountServiceMetrics = accountServiceMetrics;
this.backup = backup;
this.backupFileManager = backupFileManager;
this.helixStore = helixStore;
this.znRecordPath = znRecordPath;
}
Expand Down Expand Up @@ -84,13 +85,19 @@ interface ZKUpdater extends DataUpdater<ZNRecord> {
Map<String, String> fetchAccountMetadata() {
long startTimeMs = System.currentTimeMillis();
logger.trace("Start reading ZNRecord from path={}", znRecordPath);
ZNRecord znRecord = helixStore.get(znRecordPath, null, AccessOption.PERSISTENT);
logger.trace("Fetched ZNRecord from path={}, took time={} ms", znRecordPath, startTimeMs);
Stat stat = new Stat();
ZNRecord znRecord = helixStore.get(znRecordPath, stat, AccessOption.PERSISTENT);
logger.trace("Fetched ZNRecord from path={}, took time={} ms", znRecordPath,
System.currentTimeMillis() - startTimeMs);
if (znRecord == null) {
logger.info("The ZNRecord to read does not exist on path={}", znRecordPath);
justinlin-linkedin marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
return fetchAccountMetadataFromZNRecord(znRecord);
Map<String, String> newAccountMap = fetchAccountMetadataFromZNRecord(znRecord);
if (newAccountMap != null) {
backupFileManager.persistAccountMap(newAccountMap, stat);
}
return newAccountMap;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class AccountServiceMetrics {
public final Histogram accountUpdateConsumerTimeInMs;
public final Histogram accountUpdateToAmbryTimeInMs;
public final Histogram accountFetchFromAmbryTimeInMs;
public final Histogram backupWriteTimeInMs;
public final Histogram backupReadTimeInMs;

// Counter
public final Counter unrecognizedMessageErrorCount;
Expand Down Expand Up @@ -58,6 +60,9 @@ public AccountServiceMetrics(MetricRegistry metricRegistry) {
metricRegistry.histogram(MetricRegistry.name(HelixAccountService.class, "AccountUpdateToAmbryTimeInMs"));
accountFetchFromAmbryTimeInMs =
metricRegistry.histogram(MetricRegistry.name(HelixAccountService.class, "AccountFetchFromAmbryTimeInMs"));
backupWriteTimeInMs =
metricRegistry.histogram(MetricRegistry.name(HelixAccountService.class, "BackupWriteTimeInMs"));
backupReadTimeInMs = metricRegistry.histogram(MetricRegistry.name(HelixAccountService.class, "BackupReadTimeInMs"));

// Counter
unrecognizedMessageErrorCount =
Expand Down
Loading