Package org.lealone.hbase.engine

Examples of org.lealone.hbase.engine.HBaseSession


        super(schema, id, name, belongsToTable);
    }

    @Override
    public synchronized void flush(Session session) {
        HBaseSession s = (HBaseSession) session;
        if (s.getRegionServer() != null) {
            SessionRemote sr = null;
            CommandRemote cr = null;
            try {
                sr = SessionRemotePool.getMasterSessionRemote(s.getOriginalProperties());
                cr = SessionRemotePool.getCommandRemote(sr, "ALTER SEQUENCE " + getSQL() + " NEXT VALUE MARGIN", null, 1);
                //cr.executeUpdate();
                ResultInterface ri = cr.executeQuery(-1, false);
                ri.next();
                valueWithMargin = ri.currentRow()[0].getLong();
                value = valueWithMargin - increment * cacheSize;
            } catch (Exception e) {
                throw DbException.convert(e);
            } finally {
                SessionRemotePool.release(sr);
                if (cr != null)
                    cr.close();
            }
        } else if (s.getMaster() != null) {
            super.flush(session);
        }
    }
View Full Code Here


        if (server.getMaster() != null)
            ci.setProperty("SERVER_TYPE", "M");
        else if (server.getRegionServer() != null)
            ci.setProperty("SERVER_TYPE", "RS");
        HBaseSession session = (HBaseSession) HBaseDatabaseEngine.getInstance().createSession(ci);
        session.setMaster(server.getMaster());
        session.setRegionServer(server.getRegionServer());
        session.setOriginalProperties(originalProperties);

        return session;
    }
View Full Code Here

        if (server.getMaster() != null)
            ci.setProperty("SERVER_TYPE", "M");
        else if (server.getRegionServer() != null)
            ci.setProperty("SERVER_TYPE", "RS");
        HBaseSession session = (HBaseSession) HBaseDatabaseEngine.getInstance().createSession(ci);
        session.setMaster(server.getMaster());
        session.setRegionServer(server.getRegionServer());
        session.setOriginalProperties(originalProperties);
        ci.setSession(session);

        return new JdbcConnection(ci, false);
    }
View Full Code Here

    public void remove(Session session, Row row, boolean isUndo) {
        HBaseRow hr = (HBaseRow) row;
        if (hr.isForUpdate()) //Update这种类型的SQL不需要先删除再insert,只需直接insert即可
            return;
        try {
            HBaseSession hs = (HBaseSession) session;
            if (isUndo) {
                Put oldPut = hr.getPut();
                //撤消前面的add或remove操作
                if (oldPut != null) {
                    Delete delete = new Delete(oldPut.getRow());
                    for (Map.Entry<byte[], List<KeyValue>> e : oldPut.getFamilyMap().entrySet()) {
                        for (KeyValue kv : e.getValue()) {
                            delete.deleteColumn(e.getKey(), kv.getQualifier(), kv.getTimestamp());
                        }
                    }
                    hs.getRegionServer().delete(hr.getRegionName(), delete);
                } else
                    throw DbException.throwInternalError("oldPut is null???");
            } else {
                //正常的delete语句,
                //这种场景会把要删除的记录找出来,此时用Put的方式,不能直接用Delete,因为用Delete后如果当前事务未提交
                //那么其它并发事务就找不到之前的记录版本
                Result result = hr.getResult();
                if (result != null) {
                    Put put = hs.getTransaction().createHBasePutWithDeleteTag(defaultColumnFamilyName, result.getRow());

                    for (KeyValue kv : result.list()) {
                        if (Bytes.equals(kv.getQualifier(), HBaseConstants.TRANSACTION_META) //
                                && Bytes.equals(kv.getFamily(), defaultColumnFamilyName))
                            continue;
                        put.add(kv.getFamily(), kv.getQualifier(), null);
                    }
                    hs.getRegionServer().put(hr.getRegionName(), put);
                    hr.setPut(put);
                } else
                    throw DbException.throwInternalError("result is null???");
            }
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.lealone.hbase.engine.HBaseSession

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.