Package com.orientechnologies.orient.server.distributed

Examples of com.orientechnologies.orient.server.distributed.ODistributedException


    final String databaseName = iRequest.getDatabaseName();

    if (iNodes.isEmpty()) {
      ODistributedServerLog.error(this, getLocalNodeName(), null, DIRECTION.OUT,
          "No nodes configured for database '%s' request: %s", databaseName, iRequest);
      throw new ODistributedException("No nodes configured for partition '" + databaseName + "' request: " + iRequest);
    }

    final ODistributedConfiguration cfg = manager.getDatabaseConfiguration(databaseName);

    // TODO: REALLY STILL MATTERS THE NUMBER OF THE QUEUES?
    final IQueue<ODistributedRequest>[] reqQueues = getRequestQueues(databaseName, iNodes, iRequest.getTask());

    iRequest.setSenderNodeName(getLocalNodeName());

    int availableNodes;
    if (iRequest.getTask().isRequireNodeOnline()) {
      // CHECK THE ONLINE NODES
      availableNodes = 0;
      int i = 0;
      for (String node : iNodes) {
        if (reqQueues[i] != null && manager.isNodeAvailable(node, databaseName))
          availableNodes++;
        else {
          if (ODistributedServerLog.isDebugEnabled())
            ODistributedServerLog.debug(this, getLocalNodeName(), node, DIRECTION.OUT,
                "skip expected response from node '%s' for request %s because it's not online (queue=%s)", node, iRequest,
                reqQueues[i] != null);
        }
        ++i;
      }
    } else {
      // EXPECT ANSWER FROM ALL NODES WITH A QUEUE
      availableNodes = 0;
      for (IQueue<ODistributedRequest> q : reqQueues)
        if (q != null)
          availableNodes++;
    }

    final int quorum = calculateQuorum(iRequest, iClusterNames, cfg, availableNodes, iExecutionMode);

    final int queueSize = iNodes.size();
    int expectedSynchronousResponses = availableNodes;

    final boolean groupByResponse;
    if (iRequest.getTask().getResultStrategy() == OAbstractRemoteTask.RESULT_STRATEGY.UNION) {
      expectedSynchronousResponses = availableNodes;
      groupByResponse = false;
    } else {
      groupByResponse = true;
    }

    final boolean waitLocalNode = waitForLocalNode(cfg, iClusterNames, iNodes);

    // CREATE THE RESPONSE MANAGER
    final ODistributedResponseManager currentResponseMgr = new ODistributedResponseManager(manager, iRequest, iNodes,
        expectedSynchronousResponses, quorum, waitLocalNode,
        iRequest.getTask().getSynchronousTimeout(expectedSynchronousResponses), iRequest.getTask().getTotalTimeout(queueSize),
        groupByResponse);

    final long timeout = OGlobalConfiguration.DISTRIBUTED_QUEUE_TIMEOUT.getValueAsLong();

//    try {
//      requestLock.lock();
      try {
        // LOCK = ASSURE MESSAGES IN THE QUEUE ARE INSERTED SEQUENTIALLY AT CLUSTER LEVEL
        // BROADCAST THE REQUEST TO ALL THE NODE QUEUES

        // TODO: CAN I MOVE THIS OUTSIDE?
        iRequest.setId(msgService.getMessageIdCounter().getAndIncrement());

        if (ODistributedServerLog.isDebugEnabled())
          ODistributedServerLog.debug(this, getLocalNodeName(), iNodes.toString(), DIRECTION.OUT, "sending request %s", iRequest);

        // TODO: CAN I MOVE THIS OUTSIDE?
        msgService.registerRequest(iRequest.getId(), currentResponseMgr);

        for (IQueue<ODistributedRequest> queue : reqQueues) {
          if (queue != null)
            queue.offer(iRequest, timeout, TimeUnit.MILLISECONDS);
        }

//      } finally {
//        requestLock.unlock();
//      }

      if (ODistributedServerLog.isDebugEnabled())
        ODistributedServerLog.debug(this, getLocalNodeName(), iNodes.toString(), DIRECTION.OUT, "sent request %s", iRequest);

      Orient
          .instance()
          .getProfiler()
          .updateCounter("distributed.db." + databaseName + ".msgSent", "Number of replication messages sent from current node",
              +1, "distributed.db.*.msgSent");

      return waitForResponse(iRequest, currentResponseMgr);

    } catch (Throwable e) {
      throw new ODistributedException("Error on executing distributed request (" + iRequest + ") against database '" + databaseName
          + (iClusterNames != null ? "." + iClusterNames : "") + "' to nodes " + iNodes, e);
    }
  }
View Full Code Here


    final ODistributedServerManager.NODE_STATUS srvStatus = manager.getNodeStatus();
    if (srvStatus == ODistributedServerManager.NODE_STATUS.OFFLINE
        || srvStatus == ODistributedServerManager.NODE_STATUS.SHUTDOWNING) {
      ODistributedServerLog.error(this, getLocalNodeName(), null, DIRECTION.OUT,
          "Local server is not online (status='%s'). Request %s will be ignored", srvStatus, iRequest);
      throw new ODistributedException("Local server is not online (status='" + srvStatus + "'). Request " + iRequest
          + " will be ignored");
    }
  }
View Full Code Here

  protected int calculateQuorum(final ODistributedRequest iRequest, final Collection<String> clusterNames,
      final ODistributedConfiguration cfg, final int iAvailableNodes, final ODistributedRequest.EXECUTION_MODE iExecutionMode) {

    if (iAvailableNodes == 0 && iExecutionMode == ODistributedRequest.EXECUTION_MODE.RESPONSE)
      throw new ODistributedException("Quorum cannot be reached because there are no nodes available");

    final String clusterName = clusterNames == null || clusterNames.isEmpty() ? null : clusterNames.iterator().next();

    int quorum = 0;

    final OAbstractRemoteTask.QUORUM_TYPE quorumType = iRequest.getTask().getQuorumType();

    switch (quorumType) {
    case NONE:
      // IGNORE IT
      break;
    case READ:
      quorum = cfg.getReadQuorum(clusterName);
      break;
    case WRITE:
      quorum = cfg.getWriteQuorum(clusterName);
      break;
    case ALL:
      quorum = iAvailableNodes;
      break;
    }

    if (quorum > iAvailableNodes) {
      final boolean failureAvailableNodesLessQuorum = cfg.getFailureAvailableNodesLessQuorum(clusterName);
      if (failureAvailableNodesLessQuorum)
        throw new ODistributedException(
            "Quorum cannot be reached because it is major than available nodes and failureAvailableNodesLessQuorum=true");
      else {
        // SET THE QUORUM TO THE AVAILABLE NODE SIZE
        ODistributedServerLog.debug(this, getLocalNodeName(), null, DIRECTION.NONE,
            "quorum less then available nodes, downgrade quorum to %d", iAvailableNodes);
View Full Code Here

      // GET THE SENDER'S RESPONSE QUEUE
      final IQueue<ODistributedResponse> queue = msgService.getQueue(OHazelcastDistributedMessageService
          .getResponseQueueName(iRequest.getSenderNodeName()));

      if (!queue.offer(response, OGlobalConfiguration.DISTRIBUTED_QUEUE_TIMEOUT.getValueAsLong(), TimeUnit.MILLISECONDS))
        throw new ODistributedException("Timeout on dispatching response to the thread queue " + iRequest.getSenderNodeName());

    } catch (Exception e) {
      throw new ODistributedException("Cannot dispatch response to the thread queue " + iRequest.getSenderNodeName(), e);
    }
  }
View Full Code Here

    final OHazelcastDistributedDatabase db = messageService.getDatabase(iDatabaseName);

    if (iTargetNodes == null || iTargetNodes.isEmpty()) {
      ODistributedServerLog.error(this, getLocalNodeName(), null, DIRECTION.OUT,
          "No nodes configured for partition '%s.%s' request: %s", iDatabaseName, iClusterNames, req);
      throw new ODistributedException("No nodes configured for partition '" + iDatabaseName + "." + iClusterNames + "' request: "
          + req);
    }

    final ODistributedResponse response = db.send2Nodes(req, iClusterNames, iTargetNodes, iExecutionMode);
    if (response != null)
View Full Code Here

        if (nodeName.equals(getLocalNodeName())) {
          ODistributedServerLog.error(this, getLocalNodeName(), getNodeName(iEvent.getMember()), DIRECTION.IN,
              "Found a new node with the same name as current: '" + nodeName
                  + "'. The node has been excluded. Change the name in its config/orientdb-dserver-config.xml file");

          throw new ODistributedException("Found a new node with the same name as current: '" + nodeName
              + "'. The node has been excluded. Change the name in its config/orientdb-dserver-config.xml file");
        }

        activeNodes.put(nodeName, (Member) iEvent.getMember());
View Full Code Here

  /**
   * Executes the request on local node. In case of error returns the Exception itself
   */
  public Serializable executeOnLocalNode(final ODistributedRequest req, final ODatabaseDocumentTx database) {
    if (database != null && !(database.getStorage() instanceof ODistributedStorage))
      throw new ODistributedException("Distributed storage was not installed for database '" + database.getName()
          + "'. Implementation found: " + database.getStorage().getClass().getName());

    final OAbstractRemoteTask task = req.getTask();

    try {
View Full Code Here

        try {
          file.getParentFile().mkdirs();
          file.createNewFile();
        } catch (IOException e) {
          throw new ODistributedException("Error on creating temp database file to install locally", e);
        }

        FileOutputStream out = null;
        try {
          out = new FileOutputStream(fileName, false);

          long fileSize = writeDatabaseChunk(1, chunk, out);
          for (int chunkNum = 2; !chunk.last; chunkNum++) {
            final Object result = sendRequest(databaseName, null, Collections.singleton(r.getKey()), new OCopyDatabaseChunkTask(
                chunk.filePath, chunkNum, chunk.offset + chunk.buffer.length), EXECUTION_MODE.RESPONSE);

            if (result instanceof Boolean)
              continue;
            else if (result instanceof Exception) {
              ODistributedServerLog.error(this, getLocalNodeName(), r.getKey(), DIRECTION.IN,
                  "error on installing database %s in %s (chunk #%d)", (Exception) result, databaseName, dbPath, chunkNum);
            } else if (result instanceof ODistributedDatabaseChunk) {
              chunk = (ODistributedDatabaseChunk) result;
              fileSize += writeDatabaseChunk(chunkNum, chunk, out);
            }
          }

          ODistributedServerLog.info(this, getLocalNodeName(), null, DIRECTION.NONE, "database copied correctly, size=%s",
              OFileUtils.getSizeAsString(fileSize));

        } catch (Exception e) {
          ODistributedServerLog.error(this, getLocalNodeName(), null, DIRECTION.NONE,
              "error on transferring database '%s' to '%s'", e, databaseName, fileName);
          throw new ODistributedException("Error on transferring database", e);
        } finally {
          try {
            if (out != null) {
              out.flush();
              out.close();
            }
          } catch (IOException e) {
          }
        }

        installDatabaseOnLocalNode(distrDatabase, databaseName, dbPath, r.getKey(), fileName);
        distrDatabase.configureDatabase(false, true);

        return true;

      } else
        throw new IllegalArgumentException("Type " + value + " not supported");
    }

    throw new ODistributedException("No response received from remote nodes for auto-deploy of database");

  }
View Full Code Here

   public Object execute(final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentTx database)
       throws Exception {

     if (!getNodeSource().equals(iManager.getLocalNodeName())) {
       if (database == null)
         throw new ODistributedException("Database instance is null");

       final String databaseName = database.getName();

       final Lock lock = iManager.getLock(databaseName);
       if (lock.tryLock()) {
View Full Code Here

  public Object execute(final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentTx database)
      throws Exception {

    if (!getNodeSource().equals(iManager.getLocalNodeName())) {
      if (database == null)
        throw new ODistributedException("Database instance is null");

      final String databaseName = database.getName();

      final ODistributedConfiguration dCfg = iManager.getDatabaseConfiguration(databaseName);
      if (!clusterName.equalsIgnoreCase(dCfg.getMasterServer(clusterName)))
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.server.distributed.ODistributedException

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.