/**
 * 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 pb;

option java_package = "org.apache.hadoop.hbase.protobuf.generated";
option java_outer_classname = "WALProtos";
option java_generic_services = false;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;

import "HBase.proto";
import "Client.proto";

message WALHeader {
  optional bool has_compression = 1;
  optional bytes encryption_key = 2;
  optional bool has_tag_compression = 3;
  optional string writer_cls_name = 4;
  optional string cell_codec_cls_name = 5;
}

/*
 * Protocol buffer version of WALKey; see WALKey comment, not really a key but WALEdit header
 * for some KVs
 */
message WALKey {
  required bytes encoded_region_name = 1;
  required bytes table_name = 2;
  required uint64 log_sequence_number = 3;
  required uint64 write_time = 4;
  /*
  This parameter is deprecated in favor of clusters which
  contains the list of clusters that have consumed the change.
  It is retained so that the log created by earlier releases (0.94)
  can be read by the newer releases.
  */
  optional UUID cluster_id = 5 [deprecated=true];

  repeated FamilyScope scopes = 6;
  optional uint32 following_kv_count = 7;

  /*
  This field contains the list of clusters that have
  consumed the change
  */
  repeated UUID cluster_ids = 8;

  optional uint64 nonceGroup = 9;
  optional uint64 nonce = 10;
  optional uint64 orig_sequence_number = 11;

/*
  optional CustomEntryType custom_entry_type = 9;

  enum CustomEntryType {
    COMPACTION = 0;
  }
*/
}

enum ScopeType {
  REPLICATION_SCOPE_LOCAL = 0;
  REPLICATION_SCOPE_GLOBAL = 1;
}

message FamilyScope {
  required bytes family = 1;
  required ScopeType scope_type = 2;
}

/**
 * Custom WAL entries
 */

/**
 * Special WAL entry to hold all related to a compaction.
 * Written to WAL before completing compaction.  There is
 * sufficient info in the below message to complete later
 * the * compaction should we fail the WAL write.
 */
message CompactionDescriptor {
  required bytes table_name = 1; // TODO: WALKey already stores these, might remove
  required bytes encoded_region_name = 2;
  required bytes family_name = 3;
  repeated string compaction_input = 4; // relative to store dir
  repeated string compaction_output = 5;
  required string store_home_dir = 6; // relative to region dir
  optional bytes  region_name = 7; // full region name
}

/**
 * Special WAL entry to hold all related to a flush.
 */
message FlushDescriptor {
  enum FlushAction {
    START_FLUSH = 0;
    COMMIT_FLUSH = 1;
    ABORT_FLUSH = 2;
    CANNOT_FLUSH = 3; // marker for indicating that a flush has been requested but cannot complete
  }

  message StoreFlushDescriptor {
    required bytes family_name = 1;
    required string store_home_dir = 2; //relative to region dir
    repeated string flush_output = 3; // relative to store dir (if this is a COMMIT_FLUSH)
  }

  required FlushAction action = 1;
  required bytes table_name = 2;
  required bytes encoded_region_name = 3;
  optional uint64 flush_sequence_number = 4;
  repeated StoreFlushDescriptor store_flushes = 5;
  optional bytes  region_name = 6; // full region name
}

message StoreDescriptor {
  required bytes family_name = 1;
  required string store_home_dir = 2; //relative to region dir
  repeated string store_file = 3; // relative to store dir
  optional uint64 store_file_size_bytes = 4; // size of store file
}

/**
 * Special WAL entry used for writing bulk load events to WAL
 */
message BulkLoadDescriptor {
  required TableName table_name = 1;
  required bytes encoded_region_name = 2;
  repeated StoreDescriptor stores = 3;
  required int64 bulkload_seq_num = 4;
}

/**
 * Special WAL entry to hold all related to a region event (open/close).
 */
message RegionEventDescriptor {
  enum EventType {
    REGION_OPEN = 0;
    REGION_CLOSE = 1;
  }

  required EventType event_type = 1;
  required bytes table_name = 2;
  required bytes encoded_region_name = 3;
  optional uint64 log_sequence_number = 4;
  repeated StoreDescriptor stores = 5;
  optional ServerName server = 6;  // Server who opened the region
  optional bytes  region_name = 7; // full region name
}

/**
 * A trailer that is appended to the end of a properly closed WAL file.
 * If missing, this is either a legacy or a corrupted WAL file.
 * N.B. This trailer currently doesn't contain any information and we
 * purposefully don't expose it in the WAL APIs. It's for future growth.
 */
message WALTrailer {
}
