~ubuntu-branches/ubuntu/precise/hbase/precise

« back to all changes in this revision

Viewing changes to src/contrib/transactional/src/java/org/apache/hadoop/hbase/regionserver/transactional/THLogKey.java

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Koch
  • Date: 2010-05-06 14:20:42 UTC
  • Revision ID: james.westby@ubuntu.com-20100506142042-r3hlvgxdcpb8tynl
Tags: upstream-0.20.4+dfsg1
ImportĀ upstreamĀ versionĀ 0.20.4+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2009 The Apache Software Foundation
 
3
 *
 
4
 * Licensed to the Apache Software Foundation (ASF) under one
 
5
 * or more contributor license agreements.  See the NOTICE file
 
6
 * distributed with this work for additional information
 
7
 * regarding copyright ownership.  The ASF licenses this file
 
8
 * to you under the Apache License, Version 2.0 (the
 
9
 * "License"); you may not use this file except in compliance
 
10
 * with the License.  You may obtain a copy of the License at
 
11
 *
 
12
 *     http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
14
 * Unless required by applicable law or agreed to in writing, software
 
15
 * distributed under the License is distributed on an "AS IS" BASIS,
 
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
 * See the License for the specific language governing permissions and
 
18
 * limitations under the License.
 
19
 */
 
20
package org.apache.hadoop.hbase.regionserver.transactional;
 
21
 
 
22
import java.io.DataInput;
 
23
import java.io.DataOutput;
 
24
import java.io.IOException;
 
25
 
 
26
import org.apache.hadoop.hbase.regionserver.HLogKey;
 
27
 
 
28
public class THLogKey extends HLogKey {
 
29
 
 
30
  /** Type of Transactional op going into the HLot
 
31
   *  
 
32
   */
 
33
  public enum TrxOp {
 
34
    /** A standard operation that is transactional. KV holds the op. */
 
35
    OP((byte)2), 
 
36
    /** A transaction was committed. */
 
37
    COMMIT((byte)3), 
 
38
    /** A transaction was aborted. */
 
39
    ABORT((byte)4);
 
40
    
 
41
    private final byte opCode;
 
42
    
 
43
    private TrxOp(byte opCode) {
 
44
      this.opCode = opCode;
 
45
    }
 
46
 
 
47
    public static TrxOp fromByte(byte opCode) {
 
48
      for (TrxOp op : TrxOp.values()) {
 
49
        if (op.opCode == opCode) {
 
50
          return op;
 
51
        }
 
52
      }
 
53
      return null;
 
54
    }
 
55
 
 
56
  }
 
57
 
 
58
  private byte transactionOp = -1;
 
59
  private long transactionId = -1;
 
60
  
 
61
  public THLogKey() {
 
62
    // For Writable
 
63
  }
 
64
  
 
65
  public THLogKey(byte[] regionName, byte[] tablename, long logSeqNum, long now) {
 
66
    super(regionName, tablename, logSeqNum, now);
 
67
   }
 
68
  
 
69
  public THLogKey(byte[] regionName, byte[] tablename, long logSeqNum, long now, TrxOp op, long transactionId) {
 
70
    super(regionName, tablename, logSeqNum, now);
 
71
    this.transactionOp = op.opCode;
 
72
    this.transactionId = transactionId;
 
73
  }
 
74
 
 
75
  public TrxOp getTrxOp() {
 
76
    return TrxOp.fromByte(this.transactionOp);
 
77
  }
 
78
  
 
79
  public long getTransactionId() {
 
80
    return this.transactionId;
 
81
  }
 
82
  
 
83
  @Override
 
84
  public void write(DataOutput out) throws IOException {
 
85
    super.write(out);
 
86
    out.writeByte(transactionOp);
 
87
    out.writeLong(transactionId);
 
88
  }
 
89
  
 
90
  @Override
 
91
  public void readFields(DataInput in) throws IOException {
 
92
   super.readFields(in);
 
93
   this.transactionOp = in.readByte();
 
94
   this.transactionId = in.readLong();
 
95
  }
 
96
}