Package org.apache.hadoop.hbase.regionserver.MultiVersionConsistencyControl

Examples of org.apache.hadoop.hbase.regionserver.MultiVersionConsistencyControl.WriteEntry


    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.APPEND);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    RowLock rowLock = null;
    try {
      rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte[], List<Cell>> family : append.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());
 
            Collections.sort(family.getValue(), store.getComparator());
            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            List<Cell> results = get(get, false);
 
            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the append value

            // Avoid as much copying as possible. Every byte is copied at most
            // once.
            // Would be nice if KeyValue had scatter/gather logic
            int idx = 0;
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              KeyValue newKV;
              if (idx < results.size()
                  && CellUtil.matchingQualifier(results.get(idx),kv)) {
                KeyValue oldKv = KeyValueUtil.ensureKeyValue(results.get(idx));
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    oldKv.getValueLength() + kv.getValueLength());
                // copy in the value
                System.arraycopy(oldKv.getBuffer(), oldKv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    oldKv.getValueLength());
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(),
                    newKV.getValueOffset() + oldKv.getValueLength(),
                    kv.getValueLength());
                idx++;
              } else {
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    kv.getValueLength());
                // copy in the value
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    kv.getValueLength());
              }
              // copy in row, family, and qualifier
              System.arraycopy(kv.getBuffer(), kv.getRowOffset(),
                  newKV.getBuffer(), newKV.getRowOffset(), kv.getRowLength());
              System.arraycopy(kv.getBuffer(), kv.getFamilyOffset(),
                  newKV.getBuffer(), newKV.getFamilyOffset(),
                  kv.getFamilyLength());
              System.arraycopy(kv.getBuffer(), kv.getQualifierOffset(),
                  newKV.getBuffer(), newKV.getQualifierOffset(),
                  kv.getQualifierLength());
 
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Append update to WAL
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here


    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.INCREMENT);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    try {
      RowLock rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte [], List<Cell>> family:
              increment.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());

            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell: family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            get.setTimeRange(tr.getMin(), tr.getMax());
            List<Cell> results = get(get, false);
 
            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the increment amount
            int idx = 0;
            for (Cell kv: family.getValue()) {
              long amount = Bytes.toLong(CellUtil.cloneValue(kv));
              if (idx < results.size() && CellUtil.matchingQualifier(results.get(idx), kv)) {
                Cell c = results.get(idx);
                if(c.getValueLength() == Bytes.SIZEOF_LONG) {
                  amount += Bytes.toLong(c.getValueArray(), c.getValueOffset(), Bytes.SIZEOF_LONG);
                } else {
                  // throw DoNotRetryIOException instead of IllegalArgumentException
                  throw new org.apache.hadoop.hbase.DoNotRetryIOException(
                      "Attempted to increment field that isn't 64 bits wide");
                }
                idx++;
              }

              // Append new incremented KeyValue to list
              KeyValue newKV =
                new KeyValue(row, family.getKey(), CellUtil.cloneQualifier(kv), now, Bytes.toBytes(amount));
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Prepare WAL updates
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here

    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.APPEND);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    RowLock rowLock;
    try {
      rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte[], List<Cell>> family : append.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());

            // Sort the cells so that they match the order that they
            // appear in the Get results. Otherwise, we won't be able to
            // find the existing values if the cells are not specified
            // in order by the client since cells are in an array list.
            Collections.sort(family.getValue(), store.getComparator());
            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            List<Cell> results = get(get, false);

            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the append value

            // Avoid as much copying as possible. Every byte is copied at most
            // once.
            // Would be nice if KeyValue had scatter/gather logic
            int idx = 0;
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              KeyValue newKV;
              KeyValue oldKv = null;
              if (idx < results.size()
                  && CellUtil.matchingQualifier(results.get(idx),kv)) {
                oldKv = KeyValueUtil.ensureKeyValue(results.get(idx));
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    oldKv.getValueLength() + kv.getValueLength(),
                    oldKv.getTagsLength() + kv.getTagsLength());
                // copy in the value
                System.arraycopy(oldKv.getBuffer(), oldKv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    oldKv.getValueLength());
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(),
                    newKV.getValueOffset() + oldKv.getValueLength(),
                    kv.getValueLength());
                // copy in the tags
                System.arraycopy(oldKv.getBuffer(), oldKv.getTagsOffset(), newKV.getBuffer(),
                    newKV.getTagsOffset(), oldKv.getTagsLength());
                System.arraycopy(kv.getBuffer(), kv.getTagsOffset(), newKV.getBuffer(),
                    newKV.getTagsOffset() + oldKv.getTagsLength(), kv.getTagsLength());
                idx++;
              } else {
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    kv.getValueLength(), kv.getTagsLength());
                // copy in the value
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    kv.getValueLength());
                // copy in tags
                System.arraycopy(kv.getBuffer(), kv.getTagsOffset(), newKV.getBuffer(),
                    newKV.getTagsOffset(), kv.getTagsLength());
              }
              // copy in row, family, and qualifier
              System.arraycopy(kv.getBuffer(), kv.getRowOffset(),
                  newKV.getBuffer(), newKV.getRowOffset(), kv.getRowLength());
              System.arraycopy(kv.getBuffer(), kv.getFamilyOffset(),
                  newKV.getBuffer(), newKV.getFamilyOffset(),
                  kv.getFamilyLength());
              System.arraycopy(kv.getBuffer(), kv.getQualifierOffset(),
                  newKV.getBuffer(), newKV.getQualifierOffset(),
                  kv.getQualifierLength());

              newKV.setMvccVersion(w.getWriteNumber());
              // Give coprocessors a chance to update the new cell
              if (coprocessorHost != null) {
                newKV = KeyValueUtil.ensureKeyValue(coprocessorHost.postMutationBeforeWAL(
                    RegionObserver.MutationType.APPEND, append, oldKv, (Cell) newKV));
              }
View Full Code Here

    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.INCREMENT);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    try {
      RowLock rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte [], List<Cell>> family:
              increment.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());

            // Sort the cells so that they match the order that they
            // appear in the Get results. Otherwise, we won't be able to
            // find the existing values if the cells are not specified
            // in order by the client since cells are in an array list.
            Collections.sort(family.getValue(), store.getComparator());
            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell: family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            get.setTimeRange(tr.getMin(), tr.getMax());
            List<Cell> results = get(get, false);

            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the increment amount
            int idx = 0;
            for (Cell kv: family.getValue()) {
              long amount = Bytes.toLong(CellUtil.cloneValue(kv));
              boolean noWriteBack = (amount == 0);

              Cell c = null;
              if (idx < results.size() && CellUtil.matchingQualifier(results.get(idx), kv)) {
                c = results.get(idx);
                if(c.getValueLength() == Bytes.SIZEOF_LONG) {
                  amount += Bytes.toLong(c.getValueArray(), c.getValueOffset(), Bytes.SIZEOF_LONG);
                } else {
                  // throw DoNotRetryIOException instead of IllegalArgumentException
                  throw new org.apache.hadoop.hbase.DoNotRetryIOException(
                      "Attempted to increment field that isn't 64 bits wide");
                }
                idx++;
              }

              // Append new incremented KeyValue to list
              byte[] q = CellUtil.cloneQualifier(kv);
              byte[] val = Bytes.toBytes(amount);
              int oldCellTagsLen = (c == null) ? 0 : c.getTagsLength();
              int incCellTagsLen = kv.getTagsLength();
              KeyValue newKV = new KeyValue(row.length, family.getKey().length, q.length, now,
                  KeyValue.Type.Put, val.length, oldCellTagsLen + incCellTagsLen);
              System.arraycopy(row, 0, newKV.getBuffer(), newKV.getRowOffset(), row.length);
              System.arraycopy(family.getKey(), 0, newKV.getBuffer(), newKV.getFamilyOffset(),
                  family.getKey().length);
              System.arraycopy(q, 0, newKV.getBuffer(), newKV.getQualifierOffset(), q.length);
              // copy in the value
              System.arraycopy(val, 0, newKV.getBuffer(), newKV.getValueOffset(), val.length);
              // copy tags
              if (oldCellTagsLen > 0) {
                System.arraycopy(c.getTagsArray(), c.getTagsOffset(), newKV.getBuffer(),
                    newKV.getTagsOffset(), oldCellTagsLen);
              }
              if (incCellTagsLen > 0) {
                System.arraycopy(kv.getTagsArray(), kv.getTagsOffset(), newKV.getBuffer(),
                    newKV.getTagsOffset() + oldCellTagsLen, incCellTagsLen);
              }
              newKV.setMvccVersion(w.getWriteNumber());
              // Give coprocessors a chance to update the new cell
              if (coprocessorHost != null) {
                newKV = KeyValueUtil.ensureKeyValue(coprocessorHost.postMutationBeforeWAL(
                    RegionObserver.MutationType.INCREMENT, increment, c, (Cell) newKV));
              }
View Full Code Here

    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.APPEND);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    RowLock rowLock = null;
    try {
      rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte[], List<Cell>> family : append.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());
 
            Collections.sort(family.getValue(), store.getComparator());
            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            List<Cell> results = get(get, false);
 
            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the append value

            // Avoid as much copying as possible. Every byte is copied at most
            // once.
            // Would be nice if KeyValue had scatter/gather logic
            int idx = 0;
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              KeyValue newKV;
              if (idx < results.size()
                  && CellUtil.matchingQualifier(results.get(idx),kv)) {
                KeyValue oldKv = KeyValueUtil.ensureKeyValue(results.get(idx));
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    oldKv.getValueLength() + kv.getValueLength());
                // copy in the value
                System.arraycopy(oldKv.getBuffer(), oldKv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    oldKv.getValueLength());
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(),
                    newKV.getValueOffset() + oldKv.getValueLength(),
                    kv.getValueLength());
                idx++;
              } else {
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    kv.getValueLength());
                // copy in the value
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    kv.getValueLength());
              }
              // copy in row, family, and qualifier
              System.arraycopy(kv.getBuffer(), kv.getRowOffset(),
                  newKV.getBuffer(), newKV.getRowOffset(), kv.getRowLength());
              System.arraycopy(kv.getBuffer(), kv.getFamilyOffset(),
                  newKV.getBuffer(), newKV.getFamilyOffset(),
                  kv.getFamilyLength());
              System.arraycopy(kv.getBuffer(), kv.getQualifierOffset(),
                  newKV.getBuffer(), newKV.getQualifierOffset(),
                  kv.getQualifierLength());
 
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Append update to WAL
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here

    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.INCREMENT);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    try {
      RowLock rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte [], List<Cell>> family:
              increment.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());

            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell: family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            get.setTimeRange(tr.getMin(), tr.getMax());
            List<Cell> results = get(get, false);
 
            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the increment amount
            int idx = 0;
            for (Cell kv: family.getValue()) {
              long amount = Bytes.toLong(CellUtil.cloneValue(kv));
              if (idx < results.size() && CellUtil.matchingQualifier(results.get(idx), kv)) {
                Cell c = results.get(idx);
                if(c.getValueLength() == Bytes.SIZEOF_LONG) {
                  amount += Bytes.toLong(c.getValueArray(), c.getValueOffset(), Bytes.SIZEOF_LONG);
                } else {
                  // throw DoNotRetryIOException instead of IllegalArgumentException
                  throw new org.apache.hadoop.hbase.DoNotRetryIOException(
                      "Attempted to increment field that isn't 64 bits wide");
                }
                idx++;
              }

              // Append new incremented KeyValue to list
              KeyValue newKV =
                new KeyValue(row, family.getKey(), CellUtil.cloneQualifier(kv), now, Bytes.toBytes(amount));
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Prepare WAL updates
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here

    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.APPEND);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    RowLock rowLock = null;
    try {
      rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte[], List<Cell>> family : append.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());

            // Sort the cells so that they match the order that they
            // appear in the Get results. Otherwise, we won't be able to
            // find the existing values if the cells are not specified
            // in order by the client since cells are in an array list.
            Collections.sort(family.getValue(), store.getComparator());
            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            List<Cell> results = get(get, false);
 
            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the append value

            // Avoid as much copying as possible. Every byte is copied at most
            // once.
            // Would be nice if KeyValue had scatter/gather logic
            int idx = 0;
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              KeyValue newKV;
              if (idx < results.size()
                  && CellUtil.matchingQualifier(results.get(idx),kv)) {
                KeyValue oldKv = KeyValueUtil.ensureKeyValue(results.get(idx));
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    oldKv.getValueLength() + kv.getValueLength());
                // copy in the value
                System.arraycopy(oldKv.getBuffer(), oldKv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    oldKv.getValueLength());
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(),
                    newKV.getValueOffset() + oldKv.getValueLength(),
                    kv.getValueLength());
                idx++;
              } else {
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    kv.getValueLength());
                // copy in the value
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    kv.getValueLength());
              }
              // copy in row, family, and qualifier
              System.arraycopy(kv.getBuffer(), kv.getRowOffset(),
                  newKV.getBuffer(), newKV.getRowOffset(), kv.getRowLength());
              System.arraycopy(kv.getBuffer(), kv.getFamilyOffset(),
                  newKV.getBuffer(), newKV.getFamilyOffset(),
                  kv.getFamilyLength());
              System.arraycopy(kv.getBuffer(), kv.getQualifierOffset(),
                  newKV.getBuffer(), newKV.getQualifierOffset(),
                  kv.getQualifierLength());
 
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Append update to WAL
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here

    checkReadOnly();
    checkResources();
    // Lock row
    startRegionOperation(Operation.INCREMENT);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    try {
      RowLock rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte [], List<Cell>> family:
              increment.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());

            // Sort the cells so that they match the order that they
            // appear in the Get results. Otherwise, we won't be able to
            // find the existing values if the cells are not specified
            // in order by the client since cells are in an array list.
            Collections.sort(family.getValue(), store.getComparator());
            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell: family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            get.setTimeRange(tr.getMin(), tr.getMax());
            List<Cell> results = get(get, false);
 
            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the increment amount
            int idx = 0;
            for (Cell kv: family.getValue()) {
              long amount = Bytes.toLong(CellUtil.cloneValue(kv));
              if (idx < results.size() && CellUtil.matchingQualifier(results.get(idx), kv)) {
                Cell c = results.get(idx);
                if(c.getValueLength() == Bytes.SIZEOF_LONG) {
                  amount += Bytes.toLong(c.getValueArray(), c.getValueOffset(), Bytes.SIZEOF_LONG);
                } else {
                  // throw DoNotRetryIOException instead of IllegalArgumentException
                  throw new org.apache.hadoop.hbase.DoNotRetryIOException(
                      "Attempted to increment field that isn't 64 bits wide");
                }
                idx++;
              }

              // Append new incremented KeyValue to list
              KeyValue newKV =
                new KeyValue(row, family.getKey(), CellUtil.cloneQualifier(kv), now, Bytes.toBytes(amount));
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Prepare WAL updates
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here

    checkReadOnly();
    // Lock row
    startRegionOperation(Operation.APPEND);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    RowLock rowLock = null;
    try {
      rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte[], List<Cell>> family : append.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());
 
            Collections.sort(family.getValue(), store.getComparator());
            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            List<KeyValue> results = get(get, false);

            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the append value

            // Avoid as much copying as possible. Every byte is copied at most
            // once.
            // Would be nice if KeyValue had scatter/gather logic
            int idx = 0;
            for (Cell cell : family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              KeyValue newKV;
              if (idx < results.size()
                  && results.get(idx).matchingQualifier(kv.getBuffer(),
                      kv.getQualifierOffset(), kv.getQualifierLength())) {
                KeyValue oldKv = results.get(idx);
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    oldKv.getValueLength() + kv.getValueLength());
                // copy in the value
                System.arraycopy(oldKv.getBuffer(), oldKv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    oldKv.getValueLength());
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(),
                    newKV.getValueOffset() + oldKv.getValueLength(),
                    kv.getValueLength());
                idx++;
              } else {
                // allocate an empty kv once
                newKV = new KeyValue(row.length, kv.getFamilyLength(),
                    kv.getQualifierLength(), now, KeyValue.Type.Put,
                    kv.getValueLength());
                // copy in the value
                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
                    newKV.getBuffer(), newKV.getValueOffset(),
                    kv.getValueLength());
              }
              // copy in row, family, and qualifier
              System.arraycopy(kv.getBuffer(), kv.getRowOffset(),
                  newKV.getBuffer(), newKV.getRowOffset(), kv.getRowLength());
              System.arraycopy(kv.getBuffer(), kv.getFamilyOffset(),
                  newKV.getBuffer(), newKV.getFamilyOffset(),
                  kv.getFamilyLength());
              System.arraycopy(kv.getBuffer(), kv.getQualifierOffset(),
                  newKV.getBuffer(), newKV.getQualifierOffset(),
                  kv.getQualifierLength());
 
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Append update to WAL
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here

    checkReadOnly();
    // Lock row
    startRegionOperation(Operation.INCREMENT);
    this.writeRequestsCount.increment();
    WriteEntry w = null;
    try {
      RowLock rowLock = getRowLock(row);
      try {
        lock(this.updatesLock.readLock());
        // wait for all prior MVCC transactions to finish - while we hold the row lock
        // (so that we are guaranteed to see the latest state)
        mvcc.completeMemstoreInsert(mvcc.beginMemstoreInsert());
        // now start my own transaction
        w = mvcc.beginMemstoreInsert();
        try {
          long now = EnvironmentEdgeManager.currentTimeMillis();
          // Process each family
          for (Map.Entry<byte [], List<Cell>> family:
              increment.getFamilyCellMap().entrySet()) {

            Store store = stores.get(family.getKey());
            List<Cell> kvs = new ArrayList<Cell>(family.getValue().size());

            // Get previous values for all columns in this family
            Get get = new Get(row);
            for (Cell cell: family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              get.addColumn(family.getKey(), kv.getQualifier());
            }
            get.setTimeRange(tr.getMin(), tr.getMax());
            List<KeyValue> results = get(get, false);

            // Iterate the input columns and update existing values if they were
            // found, otherwise add new column initialized to the increment amount
            int idx = 0;
            for (Cell cell: family.getValue()) {
              KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
              long amount = Bytes.toLong(kv.getValue());
              byte [] qualifier = kv.getQualifier();
              if (idx < results.size() && results.get(idx).matchingQualifier(qualifier)) {
                kv = results.get(idx);
                if(kv.getValueLength() == Bytes.SIZEOF_LONG) {
                  amount += Bytes.toLong(kv.getBuffer(), kv.getValueOffset(), Bytes.SIZEOF_LONG);
                } else {
                  // throw DoNotRetryIOException instead of IllegalArgumentException
                  throw new org.apache.hadoop.hbase.DoNotRetryIOException(
                      "Attempted to increment field that isn't 64 bits wide");
                }
                idx++;
              }

              // Append new incremented KeyValue to list
              KeyValue newKV =
                new KeyValue(row, family.getKey(), qualifier, now, Bytes.toBytes(amount));
              newKV.setMvccVersion(w.getWriteNumber());
              kvs.add(newKV);

              // Prepare WAL updates
              if (writeToWAL) {
                if (walEdits == null) {
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.regionserver.MultiVersionConsistencyControl.WriteEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.