001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.backup.impl;
019
020import static org.apache.hadoop.hbase.backup.BackupInfo.withState;
021
022import java.io.IOException;
023import java.util.List;
024import java.util.stream.Collectors;
025import org.apache.hadoop.hbase.backup.BackupInfo;
026import org.apache.hadoop.hbase.backup.PointInTimeRestoreRequest;
027import org.apache.hadoop.hbase.client.Connection;
028import org.apache.yetus.audience.InterfaceAudience;
029
030/**
031 * Default PITR restore handler that retrieves backup metadata from the system table.
032 * <p>
033 * This implementation is used when no custom backup root directory is specified in the request.
034 */
035@InterfaceAudience.Private
036public class DefaultPitrRestoreHandler extends AbstractPitrRestoreHandler {
037
038  public DefaultPitrRestoreHandler(Connection conn, PointInTimeRestoreRequest request) {
039    super(conn, request);
040  }
041
042  /**
043   * Retrieves completed backup entries from the BackupSystemTable and converts them into
044   * {@link PitrBackupMetadata} using {@link BackupInfoAdapter}.
045   * @param request the PITR request
046   * @return list of completed backup metadata entries
047   * @throws IOException if reading from the backup system table fails
048   */
049  @Override
050  protected List<PitrBackupMetadata> getBackupMetadata(PointInTimeRestoreRequest request)
051    throws IOException {
052    try (BackupSystemTable table = new BackupSystemTable(conn)) {
053      return table.getBackupHistory(withState(BackupInfo.BackupState.COMPLETE)).stream()
054        .map(BackupInfoAdapter::new).collect(Collectors.toList());
055    }
056  }
057}