Package org.apache.hcatalog.hbase.snapshot.lock

Examples of org.apache.hcatalog.hbase.snapshot.lock.WriteLock


      transaction.setKeepAlive(writeTxnTimeout);
    }

    refreshTransactionList(transaction.getTableName());
    String lockPath = prepareLockNode(table);
    WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
      Ids.OPEN_ACL_UNSAFE);
    RMLockListener myLockListener = new RMLockListener();
    wLock.setLockListener(myLockListener);
    try {
      boolean lockGrabbed = wLock.lock();
      if (lockGrabbed == false) {
        //TO DO : Let this request queue up and try obtaining lock.
        throw new IOException(
          "Unable to obtain lock while beginning transaction. "
            + transaction.toString());
      } else {
        List<String> colFamilies = transaction.getColumnFamilies();
        FamilyRevision revisionData = transaction.getFamilyRevisionInfo();
        for (String cfamily : colFamilies) {
          String path = PathUtil.getRunningTxnInfoPath(
            baseDir, table, cfamily);
          zkUtil.updateData(path, revisionData,
            ZKUtil.UpdateMode.APPEND);
        }
      }
    } catch (KeeperException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } catch (InterruptedException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } finally {
      wLock.unlock();
    }

    return transaction;
  }
View Full Code Here


   */
  public void commitWriteTransaction(Transaction transaction) throws IOException {
    refreshTransactionList(transaction.getTableName());

    String lockPath = prepareLockNode(transaction.getTableName());
    WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
      Ids.OPEN_ACL_UNSAFE);
    RMLockListener myLockListener = new RMLockListener();
    wLock.setLockListener(myLockListener);
    try {
      boolean lockGrabbed = wLock.lock();
      if (lockGrabbed == false) {
        //TO DO : Let this request queue up and try obtaining lock.
        throw new IOException(
          "Unable to obtain lock while commiting transaction. "
            + transaction.toString());
      } else {
        String tableName = transaction.getTableName();
        List<String> colFamilies = transaction.getColumnFamilies();
        FamilyRevision revisionData = transaction.getFamilyRevisionInfo();
        for (String cfamily : colFamilies) {
          String path = PathUtil.getRunningTxnInfoPath(
            baseDir, tableName, cfamily);
          zkUtil.updateData(path, revisionData,
            ZKUtil.UpdateMode.REMOVE);
        }

      }
    } catch (KeeperException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } catch (InterruptedException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } finally {
      wLock.unlock();
    }
    LOG.info("Write Transaction committed: " + transaction.toString());
  }
View Full Code Here

   */
  public void abortWriteTransaction(Transaction transaction) throws IOException {

    refreshTransactionList(transaction.getTableName());
    String lockPath = prepareLockNode(transaction.getTableName());
    WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
      Ids.OPEN_ACL_UNSAFE);
    RMLockListener myLockListener = new RMLockListener();
    wLock.setLockListener(myLockListener);
    try {
      boolean lockGrabbed = wLock.lock();
      if (lockGrabbed == false) {
        //TO DO : Let this request queue up and try obtaining lock.
        throw new IOException(
          "Unable to obtain lock while aborting transaction. "
            + transaction.toString());
      } else {
        String tableName = transaction.getTableName();
        List<String> colFamilies = transaction.getColumnFamilies();
        FamilyRevision revisionData = transaction
          .getFamilyRevisionInfo();
        for (String cfamily : colFamilies) {
          String path = PathUtil.getRunningTxnInfoPath(
            baseDir, tableName, cfamily);
          zkUtil.updateData(path, revisionData,
            ZKUtil.UpdateMode.REMOVE);
          path = PathUtil.getAbortInformationPath(baseDir,
            tableName, cfamily);
          zkUtil.updateData(path, revisionData,
            ZKUtil.UpdateMode.APPEND);
        }

      }
    } catch (KeeperException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } catch (InterruptedException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } finally {
      wLock.unlock();
    }
    LOG.info("Write Transaction aborted: " + transaction.toString());
  }
View Full Code Here

    throws IOException {

    refreshTransactionList(transaction.getTableName());
    transaction.keepAliveTransaction();
    String lockPath = prepareLockNode(transaction.getTableName());
    WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
      Ids.OPEN_ACL_UNSAFE);
    RMLockListener myLockListener = new RMLockListener();
    wLock.setLockListener(myLockListener);
    try {
      boolean lockGrabbed = wLock.lock();
      if (lockGrabbed == false) {
        //TO DO : Let this request queue up and try obtaining lock.
        throw new IOException(
          "Unable to obtain lock for keep alive of transaction. "
            + transaction.toString());
      } else {
        String tableName = transaction.getTableName();
        List<String> colFamilies = transaction.getColumnFamilies();
        FamilyRevision revisionData = transaction.getFamilyRevisionInfo();
        for (String cfamily : colFamilies) {
          String path = PathUtil.getRunningTxnInfoPath(
            baseDir, tableName, cfamily);
          zkUtil.updateData(path, revisionData,
            ZKUtil.UpdateMode.KEEP_ALIVE);
        }

      }
    } catch (KeeperException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } catch (InterruptedException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } finally {
      wLock.unlock();
    }

  }
View Full Code Here

    return zkUtil.getTransactionList(path);
  }

  private void refreshTransactionList(String tableName) throws IOException {
    String lockPath = prepareLockNode(tableName);
    WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
      Ids.OPEN_ACL_UNSAFE);
    RMLockListener myLockListener = new RMLockListener();
    wLock.setLockListener(myLockListener);
    try {
      boolean lockGrabbed = wLock.lock();
      if (lockGrabbed == false) {
        //TO DO : Let this request queue up and try obtaining lock.
        throw new IOException(
          "Unable to obtain lock while refreshing transactions of table "
            + tableName + ".");
      } else {
        List<String> cfPaths = zkUtil
          .getColumnFamiliesOfTable(tableName);
        for (String cf : cfPaths) {
          String runningDataPath = PathUtil.getRunningTxnInfoPath(
            baseDir, tableName, cf);
          zkUtil.refreshTransactions(runningDataPath);
        }

      }
    } catch (KeeperException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } catch (InterruptedException e) {
      throw new IOException("Exception while obtaining lock.", e);
    } finally {
      wLock.unlock();
    }

  }
View Full Code Here

            transaction.setKeepAlive(writeTxnTimeout);
        }

        refreshTransactionList(transaction.getTableName());
        String lockPath = prepareLockNode(table);
        WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
            Ids.OPEN_ACL_UNSAFE);
        RMLockListener myLockListener = new RMLockListener();
        wLock.setLockListener(myLockListener);
        try {
            boolean lockGrabbed = wLock.lock();
            if (lockGrabbed == false) {
                //TO DO : Let this request queue up and try obtaining lock.
                throw new IOException(
                    "Unable to obtain lock while beginning transaction. "
                        + transaction.toString());
            } else {
                List<String> colFamilies = transaction.getColumnFamilies();
                FamilyRevision revisionData = transaction.getFamilyRevisionInfo();
                for (String cfamily : colFamilies) {
                    String path = PathUtil.getRunningTxnInfoPath(
                        baseDir, table, cfamily);
                    zkUtil.updateData(path, revisionData,
                        ZKUtil.UpdateMode.APPEND);
                }
            }
        } catch (KeeperException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } catch (InterruptedException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } finally {
            wLock.unlock();
        }

        return transaction;
    }
View Full Code Here

     */
    public void commitWriteTransaction(Transaction transaction) throws IOException {
        refreshTransactionList(transaction.getTableName());

        String lockPath = prepareLockNode(transaction.getTableName());
        WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
            Ids.OPEN_ACL_UNSAFE);
        RMLockListener myLockListener = new RMLockListener();
        wLock.setLockListener(myLockListener);
        try {
            boolean lockGrabbed = wLock.lock();
            if (lockGrabbed == false) {
                //TO DO : Let this request queue up and try obtaining lock.
                throw new IOException(
                    "Unable to obtain lock while commiting transaction. "
                        + transaction.toString());
            } else {
                String tableName = transaction.getTableName();
                List<String> colFamilies = transaction.getColumnFamilies();
                FamilyRevision revisionData = transaction.getFamilyRevisionInfo();
                for (String cfamily : colFamilies) {
                    String path = PathUtil.getRunningTxnInfoPath(
                        baseDir, tableName, cfamily);
                    zkUtil.updateData(path, revisionData,
                        ZKUtil.UpdateMode.REMOVE);
                }

            }
        } catch (KeeperException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } catch (InterruptedException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } finally {
            wLock.unlock();
        }
        LOG.info("Write Transaction committed: " + transaction.toString());
    }
View Full Code Here

     */
    public void abortWriteTransaction(Transaction transaction) throws IOException {

        refreshTransactionList(transaction.getTableName());
        String lockPath = prepareLockNode(transaction.getTableName());
        WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
            Ids.OPEN_ACL_UNSAFE);
        RMLockListener myLockListener = new RMLockListener();
        wLock.setLockListener(myLockListener);
        try {
            boolean lockGrabbed = wLock.lock();
            if (lockGrabbed == false) {
                //TO DO : Let this request queue up and try obtaining lock.
                throw new IOException(
                    "Unable to obtain lock while aborting transaction. "
                        + transaction.toString());
            } else {
                String tableName = transaction.getTableName();
                List<String> colFamilies = transaction.getColumnFamilies();
                FamilyRevision revisionData = transaction
                    .getFamilyRevisionInfo();
                for (String cfamily : colFamilies) {
                    String path = PathUtil.getRunningTxnInfoPath(
                        baseDir, tableName, cfamily);
                    zkUtil.updateData(path, revisionData,
                        ZKUtil.UpdateMode.REMOVE);
                    path = PathUtil.getAbortInformationPath(baseDir,
                        tableName, cfamily);
                    zkUtil.updateData(path, revisionData,
                        ZKUtil.UpdateMode.APPEND);
                }

            }
        } catch (KeeperException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } catch (InterruptedException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } finally {
            wLock.unlock();
        }
        LOG.info("Write Transaction aborted: " + transaction.toString());
    }
View Full Code Here

        throws IOException {

        refreshTransactionList(transaction.getTableName());
        transaction.keepAliveTransaction();
        String lockPath = prepareLockNode(transaction.getTableName());
        WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
            Ids.OPEN_ACL_UNSAFE);
        RMLockListener myLockListener = new RMLockListener();
        wLock.setLockListener(myLockListener);
        try {
            boolean lockGrabbed = wLock.lock();
            if (lockGrabbed == false) {
                //TO DO : Let this request queue up and try obtaining lock.
                throw new IOException(
                    "Unable to obtain lock for keep alive of transaction. "
                        + transaction.toString());
            } else {
                String tableName = transaction.getTableName();
                List<String> colFamilies = transaction.getColumnFamilies();
                FamilyRevision revisionData = transaction.getFamilyRevisionInfo();
                for (String cfamily : colFamilies) {
                    String path = PathUtil.getRunningTxnInfoPath(
                        baseDir, tableName, cfamily);
                    zkUtil.updateData(path, revisionData,
                        ZKUtil.UpdateMode.KEEP_ALIVE);
                }

            }
        } catch (KeeperException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } catch (InterruptedException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } finally {
            wLock.unlock();
        }

    }
View Full Code Here

        return zkUtil.getTransactionList(path);
    }

    private void refreshTransactionList(String tableName) throws IOException {
        String lockPath = prepareLockNode(tableName);
        WriteLock wLock = new WriteLock(zkUtil.getSession(), lockPath,
            Ids.OPEN_ACL_UNSAFE);
        RMLockListener myLockListener = new RMLockListener();
        wLock.setLockListener(myLockListener);
        try {
            boolean lockGrabbed = wLock.lock();
            if (lockGrabbed == false) {
                //TO DO : Let this request queue up and try obtaining lock.
                throw new IOException(
                    "Unable to obtain lock while refreshing transactions of table "
                        + tableName + ".");
            } else {
                List<String> cfPaths = zkUtil
                    .getColumnFamiliesOfTable(tableName);
                for (String cf : cfPaths) {
                    String runningDataPath = PathUtil.getRunningTxnInfoPath(
                        baseDir, tableName, cf);
                    zkUtil.refreshTransactions(runningDataPath);
                }

            }
        } catch (KeeperException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } catch (InterruptedException e) {
            throw new IOException("Exception while obtaining lock.", e);
        } finally {
            wLock.unlock();
        }

    }
View Full Code Here

TOP

Related Classes of org.apache.hcatalog.hbase.snapshot.lock.WriteLock

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.