private long getWriteId(Table table) throws LockException {
    // In case of replication, get the writeId from the source and use valid write Id list for replication.
    if (desc.getReplicationSpec().isInReplicationScope() && desc.getPartitions().get(0).getWriteId() > 0) {
      return desc.getPartitions().get(0).getWriteId();
    } else {
      AcidUtils.TableSnapshot tableSnapshot = AcidUtils.getTableSnapshot(context.getConf(), table, true);
      if (tableSnapshot != null && tableSnapshot.getWriteId() > 0) {
        return tableSnapshot.getWriteId();
      } else {
        return -1;
      }
    }
  }
Operation process of adding a partition to a table.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/partition/add/AlterTableAddPartitionOperation.java