Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Neo4j kernel is a lightweight, embedded Java database designed to
store data structured as graphs rather than tables. For more
information, see http://neo4j.org.
/**
* Copyright (c) 2002-2013 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.neo4j.kernel.impl.transaction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.atomic.AtomicInteger;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.helpers.collection.Visitor;
import org.neo4j.kernel.DeadlockDetectedException;
import org.neo4j.kernel.impl.util.ArrayMap;
import org.neo4j.kernel.impl.util.StringLogger.LineLogger;
/**
* The Resource Allocation Graph manager is used for deadlock detection. It
* keeps track of all locked resources and transactions waiting for resources.
* When a {@link RWLock} cannot give the lock to a transaction the tx has to
* wait and that may lead to a deadlock. So before the tx is put into wait mode
* the {@link RagManager#checkWaitOn} method is invoked to check if a wait of
* this transaction will lead to a deadlock.
*
* The checkWaitOn throws a {@link DeadlockDetectedException} if
* a deadlock would occur when the transaction would wait for the resource. That
* will guarantee that a deadlock never occurs on a RWLock basis.
*
* Think of the resource allocation graph as a node space. We have two node
* types, resource nodes (R) and tx/process nodes (T). When a transaction
* acquires lock on some resource a relationship is added from the resource to
* the tx (R->T) and when a transaction waits for a resource a relationship is
* added from the tx to the resource (T->R). The only thing we need to do to see
* if a deadlock occurs when some transaction waits for a resource is to
* traverse node nodespace starting on the resource and see if we can get back
* to the tx ( T1 wants to wait on R1 and R1->T2->R2->T3->R8->T1 <==>
* deadlock!).
*/
public class RagManager implements Visitor
{
// if a runtime exception is thrown from any method it means that the
// RWLock class hasn't kept the contract to the RagManager
// The contract is:
// o When a transaction gets a lock on a resource and both the readCount and
// writeCount for that transaction on the resource was 0
// RagManager.lockAcquired( resource ) must be invoked
// o When a tx releases a lock on a resource and both the readCount and
// writeCount for that transaction on the resource goes down to zero
// RagManager.lockReleased( resource ) must be invoked
// o After invoke to the checkWaitOn( resource ) method that didn't result
// in a DeadlockDetectedException the transaction must wait
// o When the transaction wakes up from waiting on a resource the
// stopWaitOn( resource ) method must be invoked
private final Map