asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiss...@apache.org
Subject [4/6] incubator-asterixdb git commit: Deadlock-free locking protocol is enabled
Date Fri, 06 May 2016 16:23:13 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/23be9068/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityInfoManager.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityInfoManager.java b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityInfoManager.java
deleted file mode 100644
index 0e607ee..0000000
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityInfoManager.java
+++ /dev/null
@@ -1,730 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.asterix.transaction.management.service.locking;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-
-/**
- * EntityInfoManager provides EntityInfo arrays backed by ByteBuffer.
- * The array grows when the slots are overflowed.
- * Also, the array shrinks according to the following shrink policy
- * : Shrink when the resource under-utilization lasts for a certain threshold time.
- *
- * @author kisskys
- */
-public class EntityInfoManager {
-
-    private ArrayList<ChildEntityInfoArrayManager> pArray;
-    private int allocChild; //used to allocate the next free EntityInfo slot.
-    private long shrinkTimer;
-    private boolean isShrinkTimerOn;
-    private int occupiedSlots;
-    private int shrinkTimerThreshold;
-
-    //    ////////////////////////////////////////////////
-    //    // begin of unit test
-    //    ////////////////////////////////////////////////
-    //
-    //    public static final int SHRINK_TIMER_THRESHOLD = 0; //for unit test
-    //
-    //    /**
-    //     * @param args
-    //     */
-    //    public static void main(String[] args) {
-    //        final int DataSize = 5000;
-    //
-    //        int i, j;
-    //        int slots = ChildEntityInfoArrayManager.NUM_OF_SLOTS;
-    //        int data[] = new int[DataSize];
-    //        EntityInfoManager eiMgr = new EntityInfoManager();
-    //
-    //        //allocate: 50
-    //        System.out.println("allocate: 50");
-    //        for (i = 0; i < 5; i++) {
-    //            for (j = i * slots; j < i * slots + slots; j++) {
-    //                data[j] = eiMgr.allocate();
-    //            }
-    //
-    //            System.out.println(eiMgr.prettyPrint());
-    //        }
-    //
-    //        //deallocate from the last child to the first child
-    //        System.out.println("deallocate from the last child to the first child");
-    //        for (i = 4; i >= 0; i--) {
-    //            for (j = i * slots + slots - 1; j >= i * slots; j--) {
-    //                eiMgr.deallocate(data[j]);
-    //            }
-    //            System.out.println(eiMgr.prettyPrint());
-    //        }
-    //
-    //        //allocate: 50
-    //        System.out.println("allocate: 50");
-    //        for (i = 0; i < 5; i++) {
-    //            for (j = i * slots; j < i * slots + slots; j++) {
-    //                data[j] = eiMgr.allocate();
-    //            }
-    //
-    //            System.out.println(eiMgr.prettyPrint());
-    //        }
-    //
-    //        //deallocate from the first child to last child
-    //        System.out.println("deallocate from the first child to last child");
-    //        for (i = 0; i < 5; i++) {
-    //            for (j = i * slots; j < i * slots + slots; j++) {
-    //                eiMgr.deallocate(data[j]);
-    //            }
-    //
-    //            System.out.println(eiMgr.prettyPrint());
-    //        }
-    //
-    //        //allocate: 50
-    //        System.out.println("allocate: 50");
-    //        for (i = 0; i < 5; i++) {
-    //            for (j = i * slots; j < i * slots + slots; j++) {
-    //                data[j] = eiMgr.allocate();
-    //            }
-    //
-    //            System.out.println(eiMgr.prettyPrint());
-    //        }
-    //
-    //        //deallocate from the first child to 4th child
-    //        System.out.println("deallocate from the first child to 4th child");
-    //        for (i = 0; i < 4; i++) {
-    //            for (j = i * slots; j < i * slots + slots; j++) {
-    //                eiMgr.deallocate(data[j]);
-    //            }
-    //
-    //            System.out.println(eiMgr.prettyPrint());
-    //        }
-    //
-    //        //allocate: 40
-    //        System.out.println("allocate: 40");
-    //        for (i = 0; i < 4; i++) {
-    //            for (j = i * slots; j < i * slots + slots; j++) {
-    //                data[j] = eiMgr.allocate();
-    //            }
-    //
-    //            System.out.println(eiMgr.prettyPrint());
-    //        }
-    //    }
-    //
-    //    ////////////////////////////////////////////////
-    //    // end of unit test
-    //    ////////////////////////////////////////////////
-
-    public EntityInfoManager(int shrinkTimerThreshold) {
-        pArray = new ArrayList<ChildEntityInfoArrayManager>();
-        pArray.add(new ChildEntityInfoArrayManager());
-        allocChild = 0;
-        occupiedSlots = 0;
-        isShrinkTimerOn = false;
-        this.shrinkTimerThreshold = shrinkTimerThreshold;
-    }
-
-    public int allocate(int jobId, int datasetId, int entityHashVal, byte lockMode) {
-        int slotNum = allocate();
-        initEntityInfo(slotNum, jobId, datasetId, entityHashVal, lockMode);
-        return slotNum;
-    }
-
-    public int allocate() {
-        if (pArray.get(allocChild).isFull()) {
-            int size = pArray.size();
-            boolean bAlloc = false;
-            ChildEntityInfoArrayManager child;
-
-            //find a deinitialized child and initialze it
-            for (int i = 0; i < size; i++) {
-                child = pArray.get(i);
-                if (child.isDeinitialized()) {
-                    child.initialize();
-                    allocChild = i;
-                    bAlloc = true;
-                    break;
-                }
-            }
-
-            //allocate new child when there is no deinitialized child
-            if (!bAlloc) {
-                pArray.add(new ChildEntityInfoArrayManager());
-                allocChild = pArray.size() - 1;
-            }
-        }
-
-        occupiedSlots++;
-        return pArray.get(allocChild).allocate() + allocChild * ChildEntityInfoArrayManager.NUM_OF_SLOTS;
-    }
-
-    void deallocate(int slotNum) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).deallocate(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-        occupiedSlots--;
-
-        if (needShrink()) {
-            shrink();
-        }
-    }
-
-    /**
-     * Shrink policy:
-     * Shrink when the resource under-utilization lasts for a certain amount of time.
-     * TODO Need to figure out which of the policies is better
-     * case1.
-     * pArray status : O x x x x x O (O is initialized, x is deinitialized)
-     * In the above status, 'CURRENT' needShrink() returns 'TRUE'
-     * even if there is nothing to shrink or deallocate.
-     * It doesn't distinguish the deinitialized children from initialized children
-     * by calculating totalNumOfSlots = pArray.size() * ChildEntityInfoArrayManager.NUM_OF_SLOTS.
-     * In other words, it doesn't subtract the deinitialized children's slots.
-     * case2.
-     * pArray status : O O x x x x x
-     * However, in the above case, if we subtract the deinitialized children's slots,
-     * needShrink() will return false even if we shrink the pArray at this case.
-     *
-     * @return
-     */
-    private boolean needShrink() {
-        int size = pArray.size();
-        int usedSlots = occupiedSlots;
-        if (usedSlots == 0) {
-            usedSlots = 1;
-        }
-
-        if (size > 1 && size * ChildEntityInfoArrayManager.NUM_OF_SLOTS / usedSlots >= 3) {
-            if (isShrinkTimerOn) {
-                if (System.currentTimeMillis() - shrinkTimer >= shrinkTimerThreshold) {
-                    isShrinkTimerOn = false;
-                    return true;
-                }
-            } else {
-                //turn on timer
-                isShrinkTimerOn = true;
-                shrinkTimer = System.currentTimeMillis();
-            }
-        } else {
-            //turn off timer
-            isShrinkTimerOn = false;
-        }
-
-        return false;
-    }
-
-    /**
-     * Shrink() may
-     * deinitialize(:deallocates ByteBuffer of child) Children(s) or
-     * shrink pArray according to the deinitialized children's contiguity status.
-     * It doesn't deinitialze or shrink more than half of children at a time.
-     */
-    private void shrink() {
-        int i;
-        int removeCount = 0;
-        int size = pArray.size();
-        int maxDecreaseCount = size / 2;
-        ChildEntityInfoArrayManager child;
-
-        //The first buffer never be deinitialized.
-        for (i = 1; i < size; i++) {
-            if (pArray.get(i).isEmpty()) {
-                pArray.get(i).deinitialize();
-            }
-        }
-
-        //remove the empty buffers from the end
-        for (i = size - 1; i >= 1; i--) {
-            child = pArray.get(i);
-            if (child.isDeinitialized()) {
-                pArray.remove(i);
-                if (++removeCount == maxDecreaseCount) {
-                    break;
-                }
-            } else {
-                break;
-            }
-        }
-
-        //reset allocChild to the first buffer
-        allocChild = 0;
-
-        isShrinkTimerOn = false;
-    }
-
-    public String prettyPrint() {
-        StringBuilder s = new StringBuilder("\n########### EntityInfoManager Status #############\n");
-        int size = pArray.size();
-        ChildEntityInfoArrayManager child;
-
-        for (int i = 0; i < size; i++) {
-            child = pArray.get(i);
-            if (child.isDeinitialized()) {
-                continue;
-            }
-            s.append("child[" + i + "]");
-            s.append(child.prettyPrint());
-        }
-        return s.toString();
-    }
-
-    public void coreDump(OutputStream os) {
-        StringBuilder sb = new StringBuilder("\n\t########### EntityLockInfoManager Status #############\n");
-        int size = pArray.size();
-        ChildEntityInfoArrayManager child;
-
-        sb.append("Number of Child: " + size + "\n");
-        for (int i = 0; i < size; i++) {
-            try {
-                child = pArray.get(i);
-                sb.append("child[" + i + "]");
-                sb.append(child.prettyPrint());
-
-                os.write(sb.toString().getBytes());
-            } catch (IOException e) {
-                //ignore IOException
-            }
-            sb = new StringBuilder();
-        }
-    }
-
-    public int getShrinkTimerThreshold() {
-        return shrinkTimerThreshold;
-    }
-
-    public void initEntityInfo(int slotNum, int jobId, int datasetId, int PKHashVal, byte lockMode) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).initEntityInfo(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, jobId, datasetId, PKHashVal, lockMode);
-    }
-
-    public boolean compareEntityInfo(int slotNum, int jobId, int datasetId, int PKHashVal) {
-        return getPKHashVal(slotNum) == PKHashVal && getDatasetId(slotNum) == datasetId && getJobId(slotNum) == jobId;
-    }
-
-    public void increaseDatasetLockCount(int slotNum) {
-        setDatasetLockCount(slotNum, (byte) (getDatasetLockCount(slotNum) + 1));
-    }
-
-    public void decreaseDatasetLockCount(int slotNum) {
-        setDatasetLockCount(slotNum, (byte) (getDatasetLockCount(slotNum) - 1));
-    }
-
-    public void increaseEntityLockCount(int slotNum) {
-        setEntityLockCount(slotNum, (byte) (getEntityLockCount(slotNum) + 1));
-    }
-
-    public void decreaseEntityLockCount(int slotNum) {
-        setEntityLockCount(slotNum, (byte) (getEntityLockCount(slotNum) - 1));
-    }
-
-    public void increaseDatasetLockCount(int slotNum, int count) {
-        setDatasetLockCount(slotNum, (byte) (getDatasetLockCount(slotNum) + count));
-    }
-
-    public void decreaseDatasetLockCount(int slotNum, int count) {
-        setDatasetLockCount(slotNum, (byte) (getDatasetLockCount(slotNum) - count));
-    }
-
-    public void increaseEntityLockCount(int slotNum, int count) {
-        setEntityLockCount(slotNum, (byte) (getEntityLockCount(slotNum) + count));
-    }
-
-    public void decreaseEntityLockCount(int slotNum, int count) {
-        setEntityLockCount(slotNum, (byte) (getEntityLockCount(slotNum) - count));
-    }
-
-    //////////////////////////////////////////////////////////////////
-    //   set/get method for each field of EntityInfo
-    //////////////////////////////////////////////////////////////////
-
-    public void setJobId(int slotNum, int id) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setJobId(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, id);
-    }
-
-    public int getJobId(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getJobId(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setDatasetId(int slotNum, int id) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setDatasetId(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, id);
-    }
-
-    public int getDatasetId(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getDatasetId(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setPKHashVal(int slotNum, int hashVal) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setPKHashVal(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, hashVal);
-    }
-
-    public int getPKHashVal(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getPKHashVal(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setDatasetLockMode(int slotNum, byte mode) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setDatasetLockMode(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, mode);
-    }
-
-    public byte getDatasetLockMode(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getDatasetLockMode(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setDatasetLockCount(int slotNum, byte count) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setDatasetLockCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, count);
-    }
-
-    public byte getDatasetLockCount(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getDatasetLockCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setEntityLockMode(int slotNum, byte mode) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setEntityLockMode(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, mode);
-    }
-
-    public byte getEntityLockMode(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getEntityLockMode(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setEntityLockCount(int slotNum, byte count) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setEntityLockCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, count);
-    }
-
-    public byte getEntityLockCount(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getEntityLockCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    //Used for Waiter/Upgrader
-    public void setNextEntityActor(int slotNum, int nextActorSlotNum) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setNextEntityActor(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, nextActorSlotNum);
-    }
-
-    //Used for Waiter/Upgrader
-    public int getNextEntityActor(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getNextEntityActor(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    //Used for Holder
-    public void setPrevEntityActor(int slotNum, int nextActorSlotNum) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setPrevEntityActor(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, nextActorSlotNum);
-    }
-
-    //Used for Holder
-    public int getPrevEntityActor(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getPrevEntityActor(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setPrevJobResource(int slotNum, int prevResourceSlotNum) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setPrevJobResource(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, prevResourceSlotNum);
-    }
-
-    public int getPrevJobResource(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getPrevJobResource(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setNextJobResource(int slotNum, int nextResourceSlotNum) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setNextJobResource(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, nextResourceSlotNum);
-    }
-
-    public int getNextJobResource(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getNextJobResource(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    //    public void setNextDatasetActor(int slotNum, int nextActorSlotNum) {
-    //        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setNextDatasetActor(
-    //                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, nextActorSlotNum);
-    //    }
-    //
-    //    public int getNextDatasetActor(int slotNum) {
-    //        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getNextDatasetActor(
-    //                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    //    }
-}
-
-/******************************************
- * EntityInfo (28 bytes)
- * ****************************************
- * int jobId
- * int datasetId
- * int PKHashValue
- * byte datasetLockMode
- * byte datasetLockCount
- * byte enitityLockMode
- * byte entityLockCount
- * int nextEntityActor : actor can be either holder/waiter/upgrader
- * int prevJobResource : resource can be either dataset or entity and a job is holding/waiting/upgrading lock(s) on it.
- * int nextJobResource : resource can be either dataset or entity and a job is holding/waiting/upgrading lock(s) on it.
- * (int nextDatasetActor : actor can be either holder/waiter/upgrader) --> not used.
- *******************************************/
-
-class ChildEntityInfoArrayManager {
-    public static final int ENTITY_INFO_SIZE = 28; //28bytes
-    public static final int NUM_OF_SLOTS = 1024; //number of entities in a buffer
-    //    public static final int NUM_OF_SLOTS = 10; //for unit test
-    public static final int BUFFER_SIZE = ENTITY_INFO_SIZE * NUM_OF_SLOTS;
-
-    //byte offset of each field of EntityInfo
-    public static final int JOB_ID_OFFSET = 0;
-    public static final int DATASET_ID_OFFSET = 4;
-    public static final int PKHASH_VAL_OFFSET = 8;
-    public static final int DATASET_LOCK_MODE_OFFSET = 12;
-    public static final int DATASET_LOCK_COUNT_OFFSET = 13;
-    public static final int ENTITY_LOCK_MODE_OFFSET = 14;
-    public static final int ENTITY_LOCK_COUNT_OFFSET = 15;
-    public static final int ENTITY_ACTOR_OFFSET = 16;
-    public static final int PREV_JOB_RESOURCE_OFFSET = 20;
-    public static final int NEXT_JOB_RESOURCE_OFFSET = 24;
-    //public static final int DATASET_ACTOR_OFFSET = 28;
-
-    //byte offset of nextFreeSlotNum which shares the same space of JobId
-    //If a slot is in use, the space is used for JobId. Otherwise, it is used for nextFreeSlotNum.
-    public static final int NEXT_FREE_SLOT_OFFSET = 0;
-
-    private ByteBuffer buffer;
-    private int freeSlotNum;
-    private int occupiedSlots; //-1 represents 'deinitialized' state.
-
-    public ChildEntityInfoArrayManager() {
-        initialize();
-    }
-
-    public void initialize() {
-        this.buffer = ByteBuffer.allocate(BUFFER_SIZE);
-        this.freeSlotNum = 0;
-        this.occupiedSlots = 0;
-
-        for (int i = 0; i < NUM_OF_SLOTS - 1; i++) {
-            setNextFreeSlot(i, i + 1);
-        }
-        setNextFreeSlot(NUM_OF_SLOTS - 1, -1); //-1 represents EOL(end of link)
-    }
-
-    public int allocate() {
-        int currentSlot = freeSlotNum;
-        freeSlotNum = getNextFreeSlot(currentSlot);
-        occupiedSlots++;
-        if (LockManager.IS_DEBUG_MODE) {
-            System.out.println(Thread.currentThread().getName() + " entity allocate: " + currentSlot);
-        }
-        return currentSlot;
-    }
-
-    public void deallocate(int slotNum) {
-        setNextFreeSlot(slotNum, freeSlotNum);
-        freeSlotNum = slotNum;
-        occupiedSlots--;
-        if (LockManager.IS_DEBUG_MODE) {
-            System.out.println(Thread.currentThread().getName() + " entity deallocate: " + slotNum);
-        }
-    }
-
-    public void deinitialize() {
-        buffer = null;
-        occupiedSlots = -1;
-    }
-
-    public boolean isDeinitialized() {
-        return occupiedSlots == -1;
-    }
-
-    public boolean isFull() {
-        return occupiedSlots == NUM_OF_SLOTS;
-    }
-
-    public boolean isEmpty() {
-        return occupiedSlots == 0;
-    }
-
-    public int getNumOfOccupiedSlots() {
-        return occupiedSlots;
-    }
-
-    public int getFreeSlotNum() {
-        return freeSlotNum;
-    }
-
-    public String prettyPrint() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("\n\toccupiedSlots:" + getNumOfOccupiedSlots());
-        sb.append("\n\tfreeSlotNum:" + getFreeSlotNum() + "\n");
-        sb.append("\tjid\t").append("did\t").append("PK\t").append("DLM\t").append("DLC\t").append("ELM\t")
-                .append("ELC\t").append("NEA\t").append("PJR\t").append("NJR\n");
-        for (int j = 0; j < ChildEntityInfoArrayManager.NUM_OF_SLOTS; j++) {
-            sb.append(j).append(": ");
-            sb.append("\t" + getJobId(j));
-            sb.append("\t" + getDatasetId(j));
-            sb.append("\t" + getPKHashVal(j));
-            sb.append("\t" + getDatasetLockMode(j));
-            sb.append("\t" + getDatasetLockCount(j));
-            sb.append("\t" + getEntityLockMode(j));
-            sb.append("\t" + getEntityLockCount(j));
-            sb.append("\t" + getNextEntityActor(j));
-            sb.append("\t" + getPrevJobResource(j));
-            sb.append("\t" + getNextJobResource(j));
-            sb.append("\n");
-        }
-        return sb.toString();
-    }
-
-    //////////////////////////////////////////////////////////////////
-    //   set/get method for each field of EntityInfo plus freeSlot
-    //////////////////////////////////////////////////////////////////
-    public void initEntityInfo(int slotNum, int jobId, int datasetId, int PKHashVal, byte lockMode) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + JOB_ID_OFFSET, jobId);
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + DATASET_ID_OFFSET, datasetId);
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + PKHASH_VAL_OFFSET, PKHashVal);
-        buffer.put(slotNum * ENTITY_INFO_SIZE + DATASET_LOCK_MODE_OFFSET, lockMode);
-        buffer.put(slotNum * ENTITY_INFO_SIZE + DATASET_LOCK_COUNT_OFFSET, (byte) 0);
-        buffer.put(slotNum * ENTITY_INFO_SIZE + ENTITY_LOCK_MODE_OFFSET, lockMode);
-        buffer.put(slotNum * ENTITY_INFO_SIZE + ENTITY_LOCK_COUNT_OFFSET, (byte) 0);
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + ENTITY_ACTOR_OFFSET, -1);
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + PREV_JOB_RESOURCE_OFFSET, -1);
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + NEXT_JOB_RESOURCE_OFFSET, -1);
-        //buffer.putInt(slotNum * ENTITY_INFO_SIZE + DATASET_ACTOR_OFFSET, -1);
-    }
-
-    public void setNextFreeSlot(int slotNum, int nextFreeSlot) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + NEXT_FREE_SLOT_OFFSET, nextFreeSlot);
-    }
-
-    public int getNextFreeSlot(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + NEXT_FREE_SLOT_OFFSET);
-    }
-
-    public void setJobId(int slotNum, int id) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + JOB_ID_OFFSET, id);
-    }
-
-    public int getJobId(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + JOB_ID_OFFSET);
-    }
-
-    public void setDatasetId(int slotNum, int id) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + DATASET_ID_OFFSET, id);
-    }
-
-    public int getDatasetId(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + DATASET_ID_OFFSET);
-    }
-
-    public void setPKHashVal(int slotNum, int hashVal) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + PKHASH_VAL_OFFSET, hashVal);
-    }
-
-    public int getPKHashVal(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + PKHASH_VAL_OFFSET);
-    }
-
-    public void setDatasetLockMode(int slotNum, byte mode) {
-        buffer.put(slotNum * ENTITY_INFO_SIZE + DATASET_LOCK_MODE_OFFSET, mode);
-    }
-
-    public byte getDatasetLockMode(int slotNum) {
-        return buffer.get(slotNum * ENTITY_INFO_SIZE + DATASET_LOCK_MODE_OFFSET);
-    }
-
-    public void setDatasetLockCount(int slotNum, byte count) {
-        buffer.put(slotNum * ENTITY_INFO_SIZE + DATASET_LOCK_COUNT_OFFSET, count);
-    }
-
-    public byte getDatasetLockCount(int slotNum) {
-        return buffer.get(slotNum * ENTITY_INFO_SIZE + DATASET_LOCK_COUNT_OFFSET);
-    }
-
-    public void setEntityLockMode(int slotNum, byte mode) {
-        buffer.put(slotNum * ENTITY_INFO_SIZE + ENTITY_LOCK_MODE_OFFSET, mode);
-    }
-
-    public byte getEntityLockMode(int slotNum) {
-        return buffer.get(slotNum * ENTITY_INFO_SIZE + ENTITY_LOCK_MODE_OFFSET);
-    }
-
-    public void setEntityLockCount(int slotNum, byte count) {
-        buffer.put(slotNum * ENTITY_INFO_SIZE + ENTITY_LOCK_COUNT_OFFSET, count);
-    }
-
-    public byte getEntityLockCount(int slotNum) {
-        return buffer.get(slotNum * ENTITY_INFO_SIZE + ENTITY_LOCK_COUNT_OFFSET);
-    }
-
-    //Used for Waiter/Upgrader
-    public void setNextEntityActor(int slotNum, int nextActorSlotNum) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + ENTITY_ACTOR_OFFSET, nextActorSlotNum);
-    }
-
-    //Used for Waiter/Upgrader
-    public int getNextEntityActor(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + ENTITY_ACTOR_OFFSET);
-    }
-
-    //Used for Holder
-    public void setPrevEntityActor(int slotNum, int nextActorSlotNum) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + ENTITY_ACTOR_OFFSET, nextActorSlotNum);
-    }
-
-    //Used for Holder
-    public int getPrevEntityActor(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + ENTITY_ACTOR_OFFSET);
-    }
-
-    public void setPrevJobResource(int slotNum, int prevResourceSlotNum) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + PREV_JOB_RESOURCE_OFFSET, prevResourceSlotNum);
-    }
-
-    public int getPrevJobResource(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + PREV_JOB_RESOURCE_OFFSET);
-    }
-
-    public void setNextJobResource(int slotNum, int prevResourceSlotNum) {
-        buffer.putInt(slotNum * ENTITY_INFO_SIZE + NEXT_JOB_RESOURCE_OFFSET, prevResourceSlotNum);
-    }
-
-    public int getNextJobResource(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + NEXT_JOB_RESOURCE_OFFSET);
-    }
-
-    //    public void setNextDatasetActor(int slotNum, int nextActorSlotNum) {
-    //        buffer.putInt(slotNum * ENTITY_INFO_SIZE + DATASET_ACTOR_OFFSET, nextActorSlotNum);
-    //    }
-    //
-    //    public int getNextDatasetActor(int slotNum) {
-    //        return buffer.getInt(slotNum * ENTITY_INFO_SIZE + DATASET_ACTOR_OFFSET);
-    //    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/23be9068/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityLockInfoManager.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityLockInfoManager.java b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityLockInfoManager.java
deleted file mode 100644
index c3de3c4..0000000
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/EntityLockInfoManager.java
+++ /dev/null
@@ -1,827 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.asterix.transaction.management.service.locking;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-
-import org.apache.asterix.transaction.management.service.transaction.TransactionManagementConstants.LockManagerConstants.LockMode;
-
-/**
- * EntityLockInfoManager provides EntityLockInfo arrays backed by ByteBuffer.
- * The array grows when the slots are overflowed.
- * Also, the array shrinks according to the following shrink policy
- * : Shrink when the resource under-utilization lasts for a certain threshold time.
- *
- * @author kisskys
- */
-public class EntityLockInfoManager {
-
-    public static final int SHRINK_TIMER_THRESHOLD = 120000; //2min
-
-    private ArrayList<ChildEntityLockInfoArrayManager> pArray;
-    private int allocChild; //used to allocate the next free EntityInfo slot.
-    private long shrinkTimer;
-    private boolean isShrinkTimerOn;
-    private int occupiedSlots;
-    private EntityInfoManager entityInfoManager;
-    LockWaiterManager lockWaiterManager;
-
-    //        ////////////////////////////////////////////////
-    //        // begin of unit test
-    //        ////////////////////////////////////////////////
-    //
-    //        public static final int SHRINK_TIMER_THRESHOLD = 0; //for unit test
-    //
-    //        /**
-    //         * @param args
-    //         */
-    //        public static void main(String[] args) {
-    //            final int DataSize = 5000;
-    //
-    //            int i, j;
-    //            int slots = ChildEntityLockInfoArrayManager.NUM_OF_SLOTS;
-    //            int data[] = new int[DataSize];
-    //            EntityLockInfoManager eliMgr = new EntityLockInfoManager();
-    //
-    //            //allocate: 50
-    //            System.out.println("allocate: 50");
-    //            for (i = 0; i < 5; i++) {
-    //                for (j = i * slots; j < i * slots + slots; j++) {
-    //                    data[j] = eliMgr.allocate();
-    //                }
-    //
-    //                System.out.println(eliMgr.prettyPrint());
-    //            }
-    //
-    //            //deallocate from the last child to the first child
-    //            System.out.println("deallocate from the last child to the first child");
-    //            for (i = 4; i >= 0; i--) {
-    //                for (j = i * slots + slots - 1; j >= i * slots; j--) {
-    //                    eliMgr.deallocate(data[j]);
-    //                }
-    //                System.out.println(eliMgr.prettyPrint());
-    //            }
-    //
-    //            //allocate: 50
-    //            System.out.println("allocate: 50");
-    //            for (i = 0; i < 5; i++) {
-    //                for (j = i * slots; j < i * slots + slots; j++) {
-    //                    data[j] = eliMgr.allocate();
-    //                }
-    //
-    //                System.out.println(eliMgr.prettyPrint());
-    //            }
-    //
-    //            //deallocate from the first child to last child
-    //            System.out.println("deallocate from the first child to last child");
-    //            for (i = 0; i < 5; i++) {
-    //                for (j = i * slots; j < i * slots + slots; j++) {
-    //                    eliMgr.deallocate(data[j]);
-    //                }
-    //
-    //                System.out.println(eliMgr.prettyPrint());
-    //            }
-    //
-    //            //allocate: 50
-    //            System.out.println("allocate: 50");
-    //            for (i = 0; i < 5; i++) {
-    //                for (j = i * slots; j < i * slots + slots; j++) {
-    //                    data[j] = eliMgr.allocate();
-    //                }
-    //
-    //                System.out.println(eliMgr.prettyPrint());
-    //            }
-    //
-    //            //deallocate from the first child to 4th child
-    //            System.out.println("deallocate from the first child to 4th child");
-    //            for (i = 0; i < 4; i++) {
-    //                for (j = i * slots; j < i * slots + slots; j++) {
-    //                    eliMgr.deallocate(data[j]);
-    //                }
-    //
-    //                System.out.println(eliMgr.prettyPrint());
-    //            }
-    //
-    //            //allocate: 40
-    //            System.out.println("allocate: 40");
-    //            for (i = 0; i < 4; i++) {
-    //                for (j = i * slots; j < i * slots + slots; j++) {
-    //                    data[j] = eliMgr.allocate();
-    //                }
-    //
-    //                System.out.println(eliMgr.prettyPrint());
-    //            }
-    //        }
-    //
-    //        ////////////////////////////////////////////////
-    //        // end of unit test
-    //        ////////////////////////////////////////////////
-
-    public EntityLockInfoManager(EntityInfoManager entityInfoManager, LockWaiterManager lockWaiterManager) {
-        pArray = new ArrayList<ChildEntityLockInfoArrayManager>();
-        pArray.add(new ChildEntityLockInfoArrayManager());
-        allocChild = 0;
-        occupiedSlots = 0;
-        isShrinkTimerOn = false;
-        this.entityInfoManager = entityInfoManager;
-        this.lockWaiterManager = lockWaiterManager;
-    }
-
-    public int allocate() {
-        if (pArray.get(allocChild).isFull()) {
-            int size = pArray.size();
-            boolean bAlloc = false;
-            ChildEntityLockInfoArrayManager child;
-
-            //find a deinitialized child and initialze it
-            for (int i = 0; i < size; i++) {
-                child = pArray.get(i);
-                if (child.isDeinitialized()) {
-                    child.initialize();
-                    allocChild = i;
-                    bAlloc = true;
-                    break;
-                }
-            }
-
-            //allocate new child when there is no deinitialized child
-            if (!bAlloc) {
-                pArray.add(new ChildEntityLockInfoArrayManager());
-                allocChild = pArray.size() - 1;
-            }
-        }
-        occupiedSlots++;
-        return pArray.get(allocChild).allocate() + allocChild * ChildEntityLockInfoArrayManager.NUM_OF_SLOTS;
-    }
-
-    void deallocate(int slotNum) {
-        pArray.get(slotNum / ChildEntityLockInfoArrayManager.NUM_OF_SLOTS).deallocate(
-                slotNum % ChildEntityLockInfoArrayManager.NUM_OF_SLOTS);
-        occupiedSlots--;
-
-        if (needShrink()) {
-            shrink();
-        }
-    }
-
-    /**
-     * Shrink policy:
-     * Shrink when the resource under-utilization lasts for a certain amount of time.
-     * TODO Need to figure out which of the policies is better
-     * case1.
-     * pArray status : O x x x x x O (O is initialized, x is deinitialized)
-     * In the above status, 'CURRENT' needShrink() returns 'TRUE'
-     * even if there is nothing to shrink or deallocate.
-     * It doesn't distinguish the deinitialized children from initialized children
-     * by calculating totalNumOfSlots = pArray.size() * ChildEntityLockInfoArrayManager.NUM_OF_SLOTS.
-     * In other words, it doesn't subtract the deinitialized children's slots.
-     * case2.
-     * pArray status : O O x x x x x
-     * However, in the above case, if we subtract the deinitialized children's slots,
-     * needShrink() will return false even if we shrink the pArray at this case.
-     *
-     * @return
-     */
-    private boolean needShrink() {
-        int size = pArray.size();
-        int usedSlots = occupiedSlots;
-        if (usedSlots == 0) {
-            usedSlots = 1;
-        }
-
-        if (size > 1 && size * ChildEntityLockInfoArrayManager.NUM_OF_SLOTS / usedSlots >= 3) {
-            if (isShrinkTimerOn) {
-                if (System.currentTimeMillis() - shrinkTimer >= SHRINK_TIMER_THRESHOLD) {
-                    isShrinkTimerOn = false;
-                    return true;
-                }
-            } else {
-                //turn on timer
-                isShrinkTimerOn = true;
-                shrinkTimer = System.currentTimeMillis();
-            }
-        } else {
-            //turn off timer
-            isShrinkTimerOn = false;
-        }
-
-        return false;
-    }
-
-    /**
-     * Shrink() may
-     * deinitialize(:deallocates ByteBuffer of child) Children(s) or
-     * shrink pArray according to the deinitialized children's contiguity status.
-     * It doesn't deinitialze or shrink more than half of children at a time.
-     */
-    private void shrink() {
-        int i;
-        int removeCount = 0;
-        int size = pArray.size();
-        int maxDecreaseCount = size / 2;
-        ChildEntityLockInfoArrayManager child;
-
-        //The first buffer never be deinitialized.
-        for (i = 1; i < size; i++) {
-            if (pArray.get(i).isEmpty()) {
-                pArray.get(i).deinitialize();
-            }
-        }
-
-        //remove the empty buffers from the end
-        for (i = size - 1; i >= 1; i--) {
-            child = pArray.get(i);
-            if (child.isDeinitialized()) {
-                pArray.remove(i);
-                if (++removeCount == maxDecreaseCount) {
-                    break;
-                }
-            } else {
-                break;
-            }
-        }
-
-        //reset allocChild to the first buffer
-        allocChild = 0;
-
-        isShrinkTimerOn = false;
-    }
-
-    public String prettyPrint() {
-        StringBuilder s = new StringBuilder("\n########### EntityLockInfoManager Status #############\n");
-        int size = pArray.size();
-        ChildEntityLockInfoArrayManager child;
-
-        for (int i = 0; i < size; i++) {
-            child = pArray.get(i);
-            if (child.isDeinitialized()) {
-                continue;
-            }
-            s.append("child[" + i + "]");
-            s.append(child.prettyPrint());
-        }
-        return s.toString();
-    }
-
-    public void coreDump(OutputStream os) {
-        StringBuilder sb = new StringBuilder("\n\t########### EntityLockInfoManager Status #############\n");
-        int size = pArray.size();
-        ChildEntityLockInfoArrayManager child;
-
-        sb.append("Number of Child: " + size + "\n");
-        for (int i = 0; i < size; i++) {
-            try {
-                child = pArray.get(i);
-                sb.append("child[" + i + "]");
-                sb.append(child.prettyPrint());
-
-                os.write(sb.toString().getBytes());
-            } catch (IOException e) {
-                //ignore IOException
-            }
-            sb = new StringBuilder();
-        }
-    }
-
-    public int getShrinkTimerThreshold() {
-        return SHRINK_TIMER_THRESHOLD;
-    }
-
-    //debugging method
-    public String printWaiters(int slotNum) {
-        StringBuilder s = new StringBuilder();
-        int waiterObjId;
-        LockWaiter waiterObj;
-        int entityInfo;
-
-        s.append("WID\tWCT\tEID\tJID\tDID\tPK\n");
-
-        waiterObjId = getFirstWaiter(slotNum);
-        while (waiterObjId != -1) {
-            waiterObj = lockWaiterManager.getLockWaiter(waiterObjId);
-            entityInfo = waiterObj.getEntityInfoSlot();
-            s.append(waiterObjId).append("\t").append(waiterObj.getWaiterCount()).append("\t").append(entityInfo)
-                    .append("\t").append(entityInfoManager.getJobId(entityInfo)).append("\t")
-                    .append(entityInfoManager.getDatasetId(entityInfo)).append("\t")
-                    .append(entityInfoManager.getPKHashVal(entityInfo)).append("\n");
-            waiterObjId = waiterObj.getNextWaiterObjId();
-        }
-
-        return s.toString();
-    }
-
-    public void addHolder(int slotNum, int holder) {
-        entityInfoManager.setPrevEntityActor(holder, getLastHolder(slotNum));
-        setLastHolder(slotNum, holder);
-    }
-
-    /**
-     * Remove holder from linked list of Actor.
-     * Also, remove the corresponding resource from linked list of resource
-     * in order to minimize JobInfo's resource link traversal.
-     *
-     * @param slotNum
-     * @param holder
-     * @param jobInfo
-     */
-    public void removeHolder(int slotNum, int holder, JobInfo jobInfo) {
-        int prev = getLastHolder(slotNum);
-        int current = -1;
-        int next;
-
-        //remove holder from linked list of Actor
-        while (prev != holder) {
-            if (LockManager.IS_DEBUG_MODE) {
-                if (prev == -1) {
-                    //shouldn't occur: debugging purpose
-                    try {
-                        throw new Exception();
-                    } catch (Exception e) {
-                        // TODO Auto-generated catch block
-                        e.printStackTrace();
-                    }
-                }
-            }
-
-            current = prev;
-            prev = entityInfoManager.getPrevEntityActor(current);
-        }
-
-        if (current != -1) {
-            //current->prev = prev->prev
-            entityInfoManager.setPrevEntityActor(current, entityInfoManager.getPrevEntityActor(prev));
-        } else {
-            //lastHolder = prev->prev
-            setLastHolder(slotNum, entityInfoManager.getPrevEntityActor(prev));
-        }
-
-        //Notice!!
-        //remove the corresponding resource from linked list of resource.
-        prev = entityInfoManager.getPrevJobResource(holder);
-        next = entityInfoManager.getNextJobResource(holder);
-
-        if (prev != -1) {
-            entityInfoManager.setNextJobResource(prev, next);
-        }
-
-        if (next != -1) {
-            entityInfoManager.setPrevJobResource(next, prev);
-        } else {
-            //This entityInfo(i.e., holder) is the last resource held by this job.
-            jobInfo.setlastHoldingResource(prev);
-        }
-
-        //jobInfo.decreaseDatasetLockCount(holder);
-    }
-
-    public void addWaiter(int slotNum, int waiterObjId) {
-        int lastObjId;
-        LockWaiter lastObj = null;
-        int firstWaiter = getFirstWaiter(slotNum);
-
-        if (firstWaiter != -1) {
-            //find the lastWaiter
-            lastObjId = firstWaiter;
-            while (lastObjId != -1) {
-                lastObj = lockWaiterManager.getLockWaiter(lastObjId);
-                lastObjId = lastObj.getNextWaiterObjId();
-            }
-            //last->next = new_waiter
-            lastObj.setNextWaiterObjId(waiterObjId);
-        } else {
-            setFirstWaiter(slotNum, waiterObjId);
-        }
-        //new_waiter->next = -1
-        lastObj = lockWaiterManager.getLockWaiter(waiterObjId);
-        lastObj.setNextWaiterObjId(-1);
-    }
-
-    public void removeWaiter(int slotNum, int waiterObjId) {
-        int currentObjId = getFirstWaiter(slotNum);
-        LockWaiter currentObj;
-        LockWaiter prevObj = null;
-        int prevObjId = -1;
-        int nextObjId;
-
-        while (currentObjId != waiterObjId) {
-
-            if (LockManager.IS_DEBUG_MODE) {
-                if (currentObjId == -1) {
-                    //shouldn't occur: debugging purpose
-                    try {
-                        throw new Exception();
-                    } catch (Exception e) {
-                        // TODO Auto-generated catch block
-                        e.printStackTrace();
-                    }
-                }
-            }
-
-            prevObj = lockWaiterManager.getLockWaiter(currentObjId);
-            prevObjId = currentObjId;
-            currentObjId = prevObj.getNextWaiterObjId();
-        }
-
-        //get current waiter object
-        currentObj = lockWaiterManager.getLockWaiter(currentObjId);
-
-        //get next waiterObjId
-        nextObjId = currentObj.getNextWaiterObjId();
-
-        if (prevObjId != -1) {
-            //prev->next = next
-            prevObj.setNextWaiterObjId(nextObjId);
-        } else {
-            //removed first waiter. firstWaiter = current->next
-            setFirstWaiter(slotNum, nextObjId);
-        }
-    }
-
-    public void addUpgrader(int slotNum, int waiterObjId) {
-        //[Notice]
-        //Even if there are multiple threads in a job try to upgrade lock mode on same resource which is entity-granule,
-        //while the first upgrader is waiting, all the incoming upgrade requests from other threads should be rejected by aborting them.
-        //Therefore, there is no actual "ADD" upgrader method. Instead, it only has "SET" upgrader method.
-        if (LockManager.IS_DEBUG_MODE) {
-            if (getUpgrader(slotNum) != -1) {
-                throw new IllegalStateException("Invalid lock upgrade request. This call should be handled as deadlock");
-            }
-        }
-
-        setUpgrader(slotNum, waiterObjId);
-    }
-
-    public void removeUpgrader(int slotNum, int waiterObjId) {
-        setUpgrader(slotNum, -1);
-    }
-
-    public boolean isUpgradeCompatible(int slotNum, byte lockMode, int entityInfo) {
-        switch (lockMode) {
-            case LockMode.X:
-                return getSCount(slotNum) - entityInfoManager.getEntityLockCount(entityInfo) == 0;
-
-            default:
-                throw new IllegalStateException("Invalid upgrade lock mode");
-        }
-    }
-
-    public boolean isCompatible(int slotNum, byte lockMode) {
-        switch (lockMode) {
-            case LockMode.X:
-                return getSCount(slotNum) == 0 && getXCount(slotNum) == 0;
-
-            case LockMode.S:
-                return getXCount(slotNum) == 0;
-
-            default:
-                throw new IllegalStateException("Invalid upgrade lock mode");
-        }
-    }
-
-    public int findEntityInfoFromHolderList(int eLockInfo, int jobId, int hashVal) {
-        int entityInfo = getLastHolder(eLockInfo);
-
-        while (entityInfo != -1) {
-            if (jobId == entityInfoManager.getJobId(entityInfo)
-                    && hashVal == entityInfoManager.getPKHashVal(entityInfo)) {
-                return entityInfo;
-            }
-            //            if (LockManager.IS_DEBUG_MODE) {
-            //                System.out.println("eLockInfo(" + eLockInfo + "),entityInfo(" + entityInfo + "), Request[" + jobId
-            //                        + "," + hashVal + "]:Result[" + entityInfoManager.getJobId(entityInfo) + ","
-            //                        + entityInfoManager.getPKHashVal(entityInfo) + "]");
-            //            }
-            entityInfo = entityInfoManager.getPrevEntityActor(entityInfo);
-        }
-
-        return -1;
-    }
-
-    public int findWaiterFromWaiterList(int eLockInfo, int jobId, int hashVal) {
-        int waiterObjId = getFirstWaiter(eLockInfo);
-        LockWaiter waiterObj;
-        int entityInfo;
-
-        while (waiterObjId != -1) {
-            waiterObj = lockWaiterManager.getLockWaiter(waiterObjId);
-            entityInfo = waiterObj.getEntityInfoSlot();
-            if (jobId == entityInfoManager.getJobId(entityInfo)
-                    && hashVal == entityInfoManager.getPKHashVal(entityInfo)) {
-                return waiterObjId;
-            }
-            waiterObjId = waiterObj.getNextWaiterObjId();
-        }
-
-        return -1;
-    }
-
-    public int findUpgraderFromUpgraderList(int eLockInfo, int jobId, int hashVal) {
-        int waiterObjId = getUpgrader(eLockInfo);
-        LockWaiter waiterObj;
-        int entityInfo;
-
-        if (waiterObjId != -1) {
-            waiterObj = lockWaiterManager.getLockWaiter(waiterObjId);
-            entityInfo = waiterObj.getEntityInfoSlot();
-            if (jobId == entityInfoManager.getJobId(entityInfo)
-                    && hashVal == entityInfoManager.getPKHashVal(entityInfo)) {
-                return waiterObjId;
-            }
-        }
-
-        return -1;
-    }
-
-    public void increaseLockCount(int slotNum, byte lockMode) {
-        switch (lockMode) {
-            case LockMode.X:
-                setXCount(slotNum, (short) (getXCount(slotNum) + 1));
-                break;
-            case LockMode.S:
-                setSCount(slotNum, (short) (getSCount(slotNum) + 1));
-                break;
-            default:
-                throw new IllegalStateException("Invalid entity lock mode " + lockMode);
-        }
-    }
-
-    public void decreaseLockCount(int slotNum, byte lockMode) {
-        switch (lockMode) {
-            case LockMode.X:
-                setXCount(slotNum, (short) (getXCount(slotNum) - 1));
-                break;
-            case LockMode.S:
-                setSCount(slotNum, (short) (getSCount(slotNum) - 1));
-                break;
-            default:
-                throw new IllegalStateException("Invalid entity lock mode " + lockMode);
-        }
-    }
-
-    public void increaseLockCount(int slotNum, byte lockMode, short count) {
-        switch (lockMode) {
-            case LockMode.X:
-                setXCount(slotNum, (short) (getXCount(slotNum) + count));
-                break;
-            case LockMode.S:
-                setSCount(slotNum, (short) (getSCount(slotNum) + count));
-                break;
-            default:
-                throw new IllegalStateException("Invalid entity lock mode " + lockMode);
-        }
-    }
-
-    public void decreaseLockCount(int slotNum, byte lockMode, short count) {
-        switch (lockMode) {
-            case LockMode.X:
-                setXCount(slotNum, (short) (getXCount(slotNum) - count));
-                break;
-            case LockMode.S:
-                setSCount(slotNum, (short) (getSCount(slotNum) - count));
-                break;
-            default:
-                throw new IllegalStateException("Invalid entity lock mode " + lockMode);
-        }
-    }
-
-    //////////////////////////////////////////////////////////////////
-    //   set/get method for each field of EntityLockInfo
-    //////////////////////////////////////////////////////////////////
-
-    public void setXCount(int slotNum, short count) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setXCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, count);
-    }
-
-    public short getXCount(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getXCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setSCount(int slotNum, short count) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setSCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, count);
-    }
-
-    public short getSCount(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getSCount(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setLastHolder(int slotNum, int holder) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setLastHolder(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, holder);
-    }
-
-    public int getLastHolder(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getLastHolder(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setFirstWaiter(int slotNum, int waiter) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setFirstWaiter(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, waiter);
-    }
-
-    public int getFirstWaiter(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getFirstWaiter(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-    public void setUpgrader(int slotNum, int upgrader) {
-        pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).setUpgrader(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS, upgrader);
-    }
-
-    public int getUpgrader(int slotNum) {
-        return pArray.get(slotNum / ChildEntityInfoArrayManager.NUM_OF_SLOTS).getUpgrader(
-                slotNum % ChildEntityInfoArrayManager.NUM_OF_SLOTS);
-    }
-
-}
-
-/******************************************
- * EntityLockInfo (16 bytes)
- * ****************************************
- * short XCount : used to represent the count of X mode lock if it is allocated. Otherwise, it represents next free slot.
- * short SCount
- * int lastHolder
- * int firstWaiter
- * int upgrader : may exist only one since there are only S and X mode lock in Entity-level
- *******************************************/
-
-class ChildEntityLockInfoArrayManager {
-    public static final int ENTITY_LOCK_INFO_SIZE = 16; //16bytes
-    public static final int NUM_OF_SLOTS = 1024; //number of entityLockInfos in a buffer
-    //public static final int NUM_OF_SLOTS = 10; //for unit test
-    public static final int BUFFER_SIZE = ENTITY_LOCK_INFO_SIZE * NUM_OF_SLOTS;
-
-    //byte offset of each field of EntityLockInfo
-    public static final int XCOUNT_OFFSET = 0;
-    public static final int SCOUNT_OFFSET = 2;
-    public static final int LAST_HOLDER_OFFSET = 4;
-    public static final int FIRST_WAITER_OFFSET = 8;
-    public static final int UPGRADER_OFFSET = 12;
-
-    //byte offset of nextFreeSlotNum which shares the same space with LastHolder field
-    //If a slot is in use, the space is used for LastHolder. Otherwise, it is used for nextFreeSlotNum.
-    public static final int NEXT_FREE_SLOT_OFFSET = 4;
-
-    private ByteBuffer buffer;
-    private int freeSlotNum;
-    private int occupiedSlots; //-1 represents 'deinitialized' state.
-
-    public ChildEntityLockInfoArrayManager() {
-        initialize();
-    }
-
-    public void initialize() {
-        this.buffer = ByteBuffer.allocate(BUFFER_SIZE);
-        this.freeSlotNum = 0;
-        this.occupiedSlots = 0;
-
-        for (int i = 0; i < NUM_OF_SLOTS - 1; i++) {
-            setNextFreeSlot(i, i + 1);
-        }
-        setNextFreeSlot(NUM_OF_SLOTS - 1, -1); //-1 represents EOL(end of link)
-    }
-
-    public int allocate() {
-        int currentSlot = freeSlotNum;
-        freeSlotNum = getNextFreeSlot(currentSlot);
-        //initialize values
-        setXCount(currentSlot, (short) 0);
-        setSCount(currentSlot, (short) 0);
-        setLastHolder(currentSlot, -1);
-        setFirstWaiter(currentSlot, -1);
-        setUpgrader(currentSlot, -1);
-        occupiedSlots++;
-        if (LockManager.IS_DEBUG_MODE) {
-            System.out.println(Thread.currentThread().getName() + " Allocated ELockInfo[" + currentSlot + "]");
-        }
-        return currentSlot;
-    }
-
-    public void deallocate(int slotNum) {
-        setNextFreeSlot(slotNum, freeSlotNum);
-        freeSlotNum = slotNum;
-        occupiedSlots--;
-        if (LockManager.IS_DEBUG_MODE) {
-            System.out.println(Thread.currentThread().getName() + " Deallocated ELockInfo[" + slotNum + "]");
-        }
-    }
-
-    public void deinitialize() {
-        buffer = null;
-        occupiedSlots = -1;
-    }
-
-    public boolean isDeinitialized() {
-        return occupiedSlots == -1;
-    }
-
-    public boolean isFull() {
-        return occupiedSlots == NUM_OF_SLOTS;
-    }
-
-    public boolean isEmpty() {
-        return occupiedSlots == 0;
-    }
-
-    public int getNumOfOccupiedSlots() {
-        return occupiedSlots;
-    }
-
-    public int getFreeSlotNum() {
-        return freeSlotNum;
-    }
-
-    public String prettyPrint() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("\n\toccupiedSlots:" + getNumOfOccupiedSlots());
-        sb.append("\n\tfreeSlotNum:" + getFreeSlotNum());
-        sb.append("\n\tX\t").append("S\t").append("LH\t").append("FW\t").append("UP\n");
-        for (int j = 0; j < ChildEntityLockInfoArrayManager.NUM_OF_SLOTS; j++) {
-            sb.append(j).append(": ");
-            sb.append("\t" + getXCount(j));
-            sb.append("\t" + getSCount(j));
-            sb.append("\t" + getLastHolder(j));
-            sb.append("\t" + getFirstWaiter(j));
-            sb.append("\t" + getUpgrader(j));
-            sb.append("\n");
-        }
-        return sb.toString();
-    }
-
-    //////////////////////////////////////////////////////////////////
-    //   set/get method for each field of EntityLockInfo plus freeSlot
-    //////////////////////////////////////////////////////////////////
-
-    public void setNextFreeSlot(int slotNum, int nextFreeSlot) {
-        buffer.putInt(slotNum * ENTITY_LOCK_INFO_SIZE + NEXT_FREE_SLOT_OFFSET, nextFreeSlot);
-    }
-
-    public int getNextFreeSlot(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_LOCK_INFO_SIZE + NEXT_FREE_SLOT_OFFSET);
-    }
-
-    public void setXCount(int slotNum, short count) {
-        buffer.putShort(slotNum * ENTITY_LOCK_INFO_SIZE + XCOUNT_OFFSET, count);
-    }
-
-    public short getXCount(int slotNum) {
-        return buffer.getShort(slotNum * ENTITY_LOCK_INFO_SIZE + XCOUNT_OFFSET);
-    }
-
-    public void setSCount(int slotNum, short count) {
-        buffer.putShort(slotNum * ENTITY_LOCK_INFO_SIZE + SCOUNT_OFFSET, count);
-    }
-
-    public short getSCount(int slotNum) {
-        return buffer.getShort(slotNum * ENTITY_LOCK_INFO_SIZE + SCOUNT_OFFSET);
-    }
-
-    public void setLastHolder(int slotNum, int holder) {
-        buffer.putInt(slotNum * ENTITY_LOCK_INFO_SIZE + LAST_HOLDER_OFFSET, holder);
-    }
-
-    public int getLastHolder(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_LOCK_INFO_SIZE + LAST_HOLDER_OFFSET);
-    }
-
-    public void setFirstWaiter(int slotNum, int waiter) {
-        buffer.putInt(slotNum * ENTITY_LOCK_INFO_SIZE + FIRST_WAITER_OFFSET, waiter);
-    }
-
-    public int getFirstWaiter(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_LOCK_INFO_SIZE + FIRST_WAITER_OFFSET);
-    }
-
-    public void setUpgrader(int slotNum, int upgrader) {
-        buffer.putInt(slotNum * ENTITY_LOCK_INFO_SIZE + UPGRADER_OFFSET, upgrader);
-    }
-
-    public int getUpgrader(int slotNum) {
-        return buffer.getInt(slotNum * ENTITY_LOCK_INFO_SIZE + UPGRADER_OFFSET);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/23be9068/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockHashTable.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockHashTable.java b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockHashTable.java
deleted file mode 100644
index bf85e69..0000000
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockHashTable.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.transaction.management.service.locking;
-
-/**
- * @author pouria Interface for a hashTable, used in the internal data
- *         structures of lockManager
- * @param <K>
- *            Type of the objects, used as keys
- * @param <V>
- *            Type of the objects, used as values
- */
-public interface ILockHashTable<K, V> {
-
-    public void put(K key, V value);
-
-    public V get(K key);
-
-    public V remove(K key);
-
-    public int getKeysetSize();
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/23be9068/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockMatrix.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockMatrix.java b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockMatrix.java
deleted file mode 100644
index e2e2e3a..0000000
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/ILockMatrix.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.transaction.management.service.locking;
-
-/**
- * @author pouria
- *         Shows: - The conflict matrix for the locking protocol (whether two
- *         lock modes conflict with each other or not on a single resource) -
- *         Whether request to convert a lock mode to a new one is a conversion
- *         (i.e. the new lock mode is stringer than the current one) or not
- *         Each lock mode is shown/interpreted as an integer
- */
-
-public interface ILockMatrix {
-
-    /**
-     * @param mask
-     *            (current/expected) lock mask on the resource
-     * @param reqLockMode
-     *            index of the requested lockMode
-     * @return true if the lock request conflicts with the mask
-     */
-    public boolean conflicts(int mask, int reqLockMode);
-
-    /**
-     * @param currentLockMode
-     * @param reqLockMode
-     * @return true if the request is a conversion
-     */
-    public boolean isConversion(int currentLockMode, int reqLockMode);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/23be9068/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/JobInfo.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/JobInfo.java b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/JobInfo.java
deleted file mode 100644
index ebbb0b8..0000000
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/locking/JobInfo.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.transaction.management.service.locking;
-
-import org.apache.asterix.common.transactions.ITransactionContext;
-import org.apache.asterix.transaction.management.service.transaction.TransactionManagementConstants.LockManagerConstants.LockMode;
-
-public class JobInfo {
-    private EntityInfoManager entityInfoManager;
-    private LockWaiterManager lockWaiterManager;
-    private ITransactionContext jobCtx;
-    private int lastHoldingResource; //resource(entity or dataset) which is held by this job lastly
-    private int firstWaitingResource; //resource(entity or dataset) which this job is waiting for
-    private int upgradingResource; //resource(entity or dataset) which this job is waiting for to upgrade
-
-    private PrimitiveIntHashMap datasetISLockHT; //used for keeping dataset-granule-lock's count acquired by this job.
-
-    public JobInfo(EntityInfoManager entityInfoManager, LockWaiterManager lockWaiterManager, ITransactionContext txnCtx) {
-        this.entityInfoManager = entityInfoManager;
-        this.lockWaiterManager = lockWaiterManager;
-        this.jobCtx = txnCtx;
-        this.lastHoldingResource = -1;
-        this.firstWaitingResource = -1;
-        this.upgradingResource = -1;
-        if (LockManager.ALLOW_ESCALATE_FROM_ENTITY_TO_DATASET) {
-            //This table maintains the number of locks acquired by this jobInfo.
-            //[Notice] But this doesn't decrease the count even if the lock is released.
-            this.datasetISLockHT = new PrimitiveIntHashMap(1 << 4, 1 << 2, Integer.MAX_VALUE);
-        }
-    }
-
-    public void addHoldingResource(int resource) {
-
-        if (LockManager.IS_DEBUG_MODE) {
-            if (entityInfoManager.getJobId(resource) != jobCtx.getJobId().getId()) {
-                throw new IllegalStateException("JobInfo(" + jobCtx.getJobId().getId() + ") has diffrent Job(JID:"
-                        + entityInfoManager.getJobId(resource) + "'s resource!!!");
-            }
-            //System.out.println(Thread.currentThread().getName()+"\tJobInfo_AddHolder:"+ resource);
-        }
-
-        if (lastHoldingResource != -1) {
-            entityInfoManager.setNextJobResource(lastHoldingResource, resource);
-        }
-        entityInfoManager.setPrevJobResource(resource, lastHoldingResource);
-        entityInfoManager.setNextJobResource(resource, -1);
-        lastHoldingResource = resource;
-    }
-
-    public void removeHoldingResource(int resource) {
-        int current = lastHoldingResource;
-        int prev;
-        int next;
-
-        if (LockManager.IS_DEBUG_MODE) {
-            if (entityInfoManager.getJobId(resource) != jobCtx.getJobId().getId()) {
-                throw new IllegalStateException("JobInfo(" + jobCtx.getJobId().getId() + ") has diffrent Job(JID:"
-                        + entityInfoManager.getJobId(resource) + "'s resource!!!");
-            }
-            //System.out.println(Thread.currentThread().getName()+"\tJobInfo_RemoveHolder:"+ resource);
-        }
-
-        while (current != resource) {
-
-            if (LockManager.IS_DEBUG_MODE) {
-                if (current == -1) {
-                    //shouldn't occur: debugging purpose
-                    try {
-                        throw new Exception();
-                    } catch (Exception e) {
-                        // TODO Auto-generated catch block
-                        e.printStackTrace();
-                    }
-                }
-            }
-
-            current = entityInfoManager.getPrevJobResource(current);
-        }
-
-        prev = entityInfoManager.getPrevJobResource(current);
-        next = entityInfoManager.getNextJobResource(current);
-        //update prev->next = next
-        if (prev != -1) {
-            entityInfoManager.setNextJobResource(prev, next);
-        }
-        if (next != -1) {
-            entityInfoManager.setPrevJobResource(next, prev);
-        }
-        if (lastHoldingResource == resource) {
-            lastHoldingResource = prev;
-        }
-
-        //decreaseDatasetLockCount(resource);
-    }
-
-    public void addWaitingResource(int waiterObjId) {
-        int lastObjId;
-        LockWaiter lastObj = null;
-
-        if (firstWaitingResource != -1) {
-            //find the lastWaiter
-            lastObjId = firstWaitingResource;
-            while (lastObjId != -1) {
-                lastObj = lockWaiterManager.getLockWaiter(lastObjId);
-                if (LockManager.IS_DEBUG_MODE) {
-                    int entityInfo = lastObj.getEntityInfoSlot();
-                    if (entityInfoManager.getJobId(entityInfo) != jobCtx.getJobId().getId()) {
-                        throw new IllegalStateException("JobInfo(" + jobCtx.getJobId().getId()
-                                + ") has diffrent Job(JID:" + entityInfoManager.getJobId(entityInfo) + "'s resource!!!");
-                    }
-                }
-                lastObjId = lastObj.getNextWaitingResourceObjId();
-            }
-            //last->next = new_waiter
-            lastObj.setNextWaitingResourceObjId(waiterObjId);
-        } else {
-            firstWaitingResource = waiterObjId;
-        }
-        //new_waiter->next = -1
-        lastObj = lockWaiterManager.getLockWaiter(waiterObjId);
-        if (LockManager.IS_DEBUG_MODE) {
-            int entityInfo = lastObj.getEntityInfoSlot();
-            if (entityInfoManager.getJobId(entityInfo) != jobCtx.getJobId().getId()) {
-                throw new IllegalStateException("JobInfo(" + jobCtx.getJobId().getId() + ") has diffrent Job(JID:"
-                        + entityInfoManager.getJobId(entityInfo) + "'s resource!!!");
-            }
-        }
-        lastObj.setNextWaitingResourceObjId(-1);
-
-        //        if (LockManager.IS_DEBUG_MODE) {
-        //            System.out.println(Thread.currentThread().getName()+"\tJobInfo_AddWaiter:"+ waiterObjId + ", FirstWaiter:"+firstWaitingResource);
-        //        }
-    }
-
-    public void removeWaitingResource(int waiterObjId) {
-        int currentObjId = firstWaitingResource;
-        LockWaiter currentObj;
-        LockWaiter prevObj = null;
-        int prevObjId = -1;
-        int nextObjId;
-
-        while (currentObjId != waiterObjId) {
-
-            if (LockManager.IS_DEBUG_MODE) {
-                if (currentObjId == -1) {
-                    //shouldn't occur: debugging purpose
-                    try {
-                        throw new Exception();
-                    } catch (Exception e) {
-                        // TODO Auto-generated catch block
-                        e.printStackTrace();
-                    }
-                }
-            }
-
-            prevObj = lockWaiterManager.getLockWaiter(currentObjId);
-            prevObjId = currentObjId;
-            currentObjId = prevObj.getNextWaitingResourceObjId();
-        }
-
-        //get current waiter object
-        currentObj = lockWaiterManager.getLockWaiter(currentObjId);
-
-        if (LockManager.IS_DEBUG_MODE) {
-            int entityInfo = currentObj.getEntityInfoSlot();
-            if (entityInfoManager.getJobId(entityInfo) != jobCtx.getJobId().getId()) {
-                throw new IllegalStateException("JobInfo(" + jobCtx.getJobId().getId() + ") has diffrent Job(JID:"
-                        + entityInfoManager.getJobId(entityInfo) + "'s resource!!!");
-            }
-        }
-
-        //get next waiterObjId
-        nextObjId = currentObj.getNextWaitingResourceObjId();
-
-        if (prevObjId != -1) {
-            //prev->next = next
-            prevObj.setNextWaitingResourceObjId(nextObjId);
-        } else {
-            //removed first waiter. firstWaiter = current->next
-            firstWaitingResource = nextObjId;
-        }
-
-        //        if (LockManager.IS_DEBUG_MODE) {
-        //            System.out.println(Thread.currentThread().getName()+"\tJobInfo_RemoveWaiter:"+ waiterObjId + ", FirstWaiter:"+firstWaitingResource);
-        //        }
-    }
-
-    public void increaseDatasetISLockCount(int datasetId) {
-        int count = datasetISLockHT.get(datasetId);
-        if (count == -1) {
-            datasetISLockHT.put(datasetId, 1);
-        } else {
-            datasetISLockHT.upsert(datasetId, count + 1);
-        }
-    }
-
-    public void decreaseDatasetISLockCount(int datasetId, int entityToDatasetLockEscalationThreshold) {
-        int count = datasetISLockHT.get(datasetId);
-        if (count >= entityToDatasetLockEscalationThreshold) {
-            //do not decrease the count since it is already escalated.
-        } else if (count > 1) {
-            datasetISLockHT.upsert(datasetId, count - 1);
-        } else if (count == 1) {
-            datasetISLockHT.remove(datasetId);
-        } else if (count <= 0) {
-            throw new IllegalStateException("Illegal state of datasetLock count(" + count + ") in JobInfo's dLockHT");
-        }
-    }
-
-    public int getDatasetISLockCount(int datasetId) {
-        int count = datasetISLockHT.get(datasetId);
-        if (count == -1) {
-            return 0;
-        } else {
-            return count;
-        }
-    }
-
-    /**********************************************************************************
-     * public boolean isDatasetLockGranted(int datasetId) {
-     * return dLockHT.get(datasetId) == -1 ? false : true;
-     * }
-     **********************************************************************************/
-
-    public boolean isDatasetLockGranted(int datasetId, byte lockMode) {
-        int entityInfo = lastHoldingResource;
-        byte datasetLockMode;
-
-        while (entityInfo != -1) {
-            datasetLockMode = entityInfoManager.getDatasetLockMode(entityInfo);
-            datasetLockMode = entityInfoManager.getPKHashVal(entityInfo) == -1 ? datasetLockMode
-                    : datasetLockMode == LockMode.S ? LockMode.IS : LockMode.IX;
-            if (entityInfoManager.getDatasetId(entityInfo) == datasetId
-                    && isStrongerOrEqualToLockMode(datasetLockMode, lockMode)) {
-                return true;
-            }
-            entityInfo = entityInfoManager.getPrevJobResource(entityInfo);
-        }
-        return false;
-    }
-
-    //check whether LockMode modeA is stronger than or equal to LockMode modeB
-    private boolean isStrongerOrEqualToLockMode(byte modeA, byte modeB) {
-        switch (modeB) {
-            case LockMode.X:
-                return modeA == LockMode.X;
-
-            case LockMode.IX:
-                return modeA == LockMode.IX || modeA == LockMode.X;
-
-            case LockMode.S:
-                return modeA == LockMode.S || modeA == LockMode.X;
-
-            case LockMode.IS:
-                return true;
-
-            default:
-                throw new IllegalStateException("Unsupported dataset lock mode.");
-        }
-    }
-
-    public String printHoldingResource() {
-        StringBuilder s = new StringBuilder();
-        int entityInfo = lastHoldingResource;
-
-        while (entityInfo != -1) {
-            s.append("entityInfo[").append(entityInfo).append("] ");
-            s.append(entityInfoManager.getJobId(entityInfo)).append(" ");
-            s.append(entityInfoManager.getDatasetId(entityInfo)).append(" ");
-            s.append(entityInfoManager.getPKHashVal(entityInfo)).append(" ");
-            s.append(entityInfoManager.getDatasetLockMode(entityInfo)).append(" ");
-            s.append(entityInfoManager.getDatasetLockCount(entityInfo)).append(" ");
-            s.append(entityInfoManager.getEntityLockCount(entityInfo)).append(" ");
-            s.append(entityInfoManager.getEntityLockMode(entityInfo)).append(" ");
-            s.append("\n");
-            entityInfo = entityInfoManager.getPrevJobResource(entityInfo);
-        }
-        return s.toString();
-    }
-
-    public String coreDump() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("\n\t datasetISLockHT");
-        sb.append(datasetISLockHT.prettyPrint());
-        sb.append("\n\t firstWaitingResource: " + firstWaitingResource);
-        sb.append("\n\t lastHoldingResource: " + lastHoldingResource);
-        sb.append("\n\t upgradingResource: " + upgradingResource);
-        sb.append("\n\t jobCtx.jobId: " + jobCtx.getJobId());
-        return sb.toString();
-    }
-
-    /////////////////////////////////////////////////////////
-    //  set/get method for private variable
-    /////////////////////////////////////////////////////////
-    public void setlastHoldingResource(int resource) {
-        lastHoldingResource = resource;
-    }
-
-    public int getLastHoldingResource() {
-        return lastHoldingResource;
-    }
-
-    public void setFirstWaitingResource(int resource) {
-        firstWaitingResource = resource;
-    }
-
-    public int getFirstWaitingResource() {
-        return firstWaitingResource;
-    }
-
-    public void setUpgradingResource(int resource) {
-        upgradingResource = resource;
-    }
-
-    public int getUpgradingResource() {
-        return upgradingResource;
-    }
-}


Mime
View raw message