Search in sources :

Example 66 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OAbstractProfiler method dumpEnvironment.

public static String dumpEnvironment() {
    final StringBuilder buffer = new StringBuilder();
    final Runtime runtime = Runtime.getRuntime();
    final long freeSpaceInMB = new File(".").getFreeSpace();
    final long totalSpaceInMB = new File(".").getTotalSpace();
    int stgs = 0;
    long diskCacheUsed = 0;
    long diskCacheTotal = 0;
    for (OStorage stg : Orient.instance().getStorages()) {
        if (stg instanceof OLocalPaginatedStorage) {
            diskCacheUsed += ((OLocalPaginatedStorage) stg).getReadCache().getUsedMemory();
            diskCacheTotal += OGlobalConfiguration.DISK_CACHE_SIZE.getValueAsLong() * 1024 * 1024;
            stgs++;
        }
    }
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName osMBeanName = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
        if (mbs.isInstanceOf(osMBeanName, "com.sun.management.OperatingSystemMXBean")) {
            final long osTotalMem = ((Number) mbs.getAttribute(osMBeanName, "TotalPhysicalMemorySize")).longValue();
            final long osUsedMem = osTotalMem - ((Number) mbs.getAttribute(osMBeanName, "FreePhysicalMemorySize")).longValue();
            buffer.append(String.format("OrientDB Memory profiler: HEAP=%s of %s - DISKCACHE (%s dbs)=%s of %s - OS=%s of %s - FS=%s of %s", OFileUtils.getSizeAsString(runtime.totalMemory() - runtime.freeMemory()), OFileUtils.getSizeAsString(runtime.maxMemory()), stgs, OFileUtils.getSizeAsString(diskCacheUsed), OFileUtils.getSizeAsString(diskCacheTotal), OFileUtils.getSizeAsString(osUsedMem), OFileUtils.getSizeAsString(osTotalMem), OFileUtils.getSizeAsString(freeSpaceInMB), OFileUtils.getSizeAsString(totalSpaceInMB)));
            return buffer.toString();
        }
    } catch (Exception e) {
    // Nothing to do. Proceed with default output
    }
    buffer.append(String.format("OrientDB Memory profiler: Heap=%s of %s - DiskCache (%s dbs)=%s of %s - FS=%s of %s", OFileUtils.getSizeAsString(runtime.totalMemory() - runtime.freeMemory()), OFileUtils.getSizeAsString(runtime.maxMemory()), stgs, OFileUtils.getSizeAsString(diskCacheUsed), OFileUtils.getSizeAsString(diskCacheTotal), OFileUtils.getSizeAsString(freeSpaceInMB), OFileUtils.getSizeAsString(totalSpaceInMB)));
    return buffer.toString();
}
Also used : OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) OStorage(com.orientechnologies.orient.core.storage.OStorage) File(java.io.File) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 67 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class Orient method loadStorage.

public OStorage loadStorage(String iURL) {
    if (iURL == null || iURL.length() == 0)
        throw new IllegalArgumentException("URL missed");
    if (iURL.endsWith("/"))
        iURL = iURL.substring(0, iURL.length() - 1);
    // SEARCH FOR ENGINE
    int pos = iURL.indexOf(':');
    if (pos <= 0)
        throw new OConfigurationException("Error in database URL: the engine was not specified. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL);
    final String engineName = iURL.substring(0, pos);
    engineLock.readLock().lock();
    try {
        final OEngine engine = engines.get(engineName.toLowerCase());
        if (engine == null)
            throw new OConfigurationException("Error on opening database: the engine '" + engineName + "' was not found. URL was: " + iURL + ". Registered engines are: " + engines.keySet());
        if (!engine.isRunning()) {
            final List<String> knownEngines = new ArrayList<String>(engines.keySet());
            if (!startEngine(engine))
                throw new OConfigurationException("Error on opening database: the engine '" + engineName + "' was unable to start. URL was: " + iURL + ". Registered engines was: " + knownEngines);
        }
        // SEARCH FOR DB-NAME
        iURL = iURL.substring(pos + 1);
        if (isWindowsOS()) {
            // WINDOWS ONLY: REMOVE DOUBLE SLASHES NOT AS PREFIX (WINDOWS PATH COULD NEED STARTING FOR "\\". EXAMPLE: "\\mydrive\db").
            // AT
            // THIS LEVEL BACKSLASHES ARRIVES AS SLASHES
            iURL = iURL.charAt(0) + iURL.substring(1).replace("//", "/");
        } else
            // REMOVE ANY //
            iURL = iURL.replace("//", "/");
        pos = iURL.indexOf('?');
        Map<String, String> parameters = null;
        String dbPath;
        if (pos > 0) {
            dbPath = iURL.substring(0, pos);
            iURL = iURL.substring(pos + 1);
            // PARSE PARAMETERS
            parameters = new HashMap<String, String>();
            String[] pairs = iURL.split("&");
            String[] kv;
            for (String pair : pairs) {
                kv = pair.split("=");
                if (kv.length < 2)
                    throw new OConfigurationException("Error on opening database: parameter has no value. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL);
                parameters.put(kv[0], kv[1]);
            }
        } else
            dbPath = iURL;
        if (registerDatabaseByPath) {
            try {
                dbPath = new File(dbPath).getCanonicalPath();
            } catch (IOException e) {
            // IGNORE IT
            }
        }
        final String dbName = registerDatabaseByPath ? dbPath : engine.getNameFromPath(dbPath);
        OStorage storage;
        // SEARCH IF ALREADY USED
        storage = storages.get(dbName);
        if (storage == null) {
            do {
                storage = engine.createStorage(dbPath, parameters);
            } while ((storage instanceof OIdentifiableStorage) && storageIds.putIfAbsent(((OIdentifiableStorage) storage).getId(), Boolean.TRUE) != null);
            final OStorage oldStorage = storages.putIfAbsent(dbName, storage);
            if (oldStorage != null)
                storage = oldStorage;
            for (OOrientListener l : browseListeners()) l.onStorageRegistered(storage);
        }
        return storage;
    } finally {
        engineLock.readLock().unlock();
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) IOException(java.io.IOException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OEngine(com.orientechnologies.orient.core.engine.OEngine) OIdentifiableStorage(com.orientechnologies.orient.core.storage.OIdentifiableStorage) File(java.io.File)

Example 68 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class Orient method unregisterStorage.

public void unregisterStorage(final OStorage storage) {
    if (!active)
        // SHUTDOWNING OR NOT ACTIVE: RETURN
        return;
    if (storage == null)
        return;
    engineLock.writeLock().lock();
    try {
        // UNREGISTER ALL THE LISTENER ONE BY ONE AVOIDING SELF-RECURSION BY REMOVING FROM THE LIST
        final Iterable<OOrientListener> listenerCopy = getListenersCopy();
        for (final OOrientListener l : listenerCopy) {
            unregisterListener(l);
            l.onStorageUnregistered(storage);
        }
        final List<String> storagesToRemove = new ArrayList<String>();
        for (Entry<String, OStorage> s : storages.entrySet()) {
            if (s.getValue().equals(storage))
                storagesToRemove.add(s.getKey());
        }
        for (String dbName : storagesToRemove) storages.remove(dbName);
        // UNREGISTER STORAGE FROM ENGINES IN CASE IS CACHED
        for (OEngine engine : engines.values()) {
            engine.removeStorage(storage);
        }
    } finally {
        engineLock.writeLock().unlock();
    }
}
Also used : OEngine(com.orientechnologies.orient.core.engine.OEngine) OStorage(com.orientechnologies.orient.core.storage.OStorage)

Example 69 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class ODatabaseImport method migrateLinksInImportedDocuments.

private void migrateLinksInImportedDocuments() throws IOException {
    listener.onMessage("\n\nStarted migration of links (-migrateLinks=true). Links are going to be updated according to new RIDs:");
    final long begin = System.currentTimeMillis();
    long last = begin;
    long documentsLastLap = 0;
    long totalDocuments = 0;
    Collection<String> clusterNames = database.getClusterNames();
    for (String clusterName : clusterNames) {
        if (OMetadataDefault.CLUSTER_INDEX_NAME.equals(clusterName) || OMetadataDefault.CLUSTER_INTERNAL_NAME.equals(clusterName) || OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME.equals(clusterName))
            continue;
        long documents = 0;
        String prefix = "";
        listener.onMessage("\n- Cluster " + clusterName + "...");
        final int clusterId = database.getClusterIdByName(clusterName);
        final long clusterRecords = database.countClusterElements(clusterId);
        OStorage storage = database.getStorage();
        OPhysicalPosition[] positions = storage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(0));
        while (positions.length > 0) {
            for (OPhysicalPosition position : positions) {
                ORecord record = database.load(new ORecordId(clusterId, position.clusterPosition));
                if (record instanceof ODocument) {
                    ODocument document = (ODocument) record;
                    rewriteLinksInDocument(document);
                    documents++;
                    documentsLastLap++;
                    totalDocuments++;
                    final long now = System.currentTimeMillis();
                    if (now - last > IMPORT_RECORD_DUMP_LAP_EVERY_MS) {
                        listener.onMessage(String.format("\n--- Migrated %,d of %,d records (%,.2f/sec)", documents, clusterRecords, (float) documentsLastLap * 1000 / (float) IMPORT_RECORD_DUMP_LAP_EVERY_MS));
                        // RESET LAP COUNTERS
                        last = now;
                        documentsLastLap = 0;
                        prefix = "\n---";
                    }
                }
            }
            positions = storage.higherPhysicalPositions(clusterId, positions[positions.length - 1]);
        }
        listener.onMessage(String.format("%s Completed migration of %,d records in current cluster", prefix, documents));
    }
    listener.onMessage(String.format("\nTotal links updated: %,d", totalDocuments));
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OStorage(com.orientechnologies.orient.core.storage.OStorage) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 70 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OIndexManagerShared method createIndex.

/**
   * Create a new index.
   * <p>
   * May require quite a long time if big amount of data should be indexed.
   *
   * @param iName             name of index
   * @param type              index type. Specified by plugged index factories.
   * @param indexDefinition   metadata that describes index structure
   * @param clusterIdsToIndex ids of clusters that index should track for changes.
   * @param progressListener  listener to track task progress.
   * @param metadata          document with additional properties that can be used by index engine.
   * @param algorithm         tip to an index factory what algorithm to use
   *
   * @return a newly created index instance
   */
public OIndex<?> createIndex(final String iName, String type, final OIndexDefinition indexDefinition, final int[] clusterIdsToIndex, OProgressListener progressListener, ODocument metadata, String algorithm) {
    if (getDatabase().getTransaction().isActive())
        throw new IllegalStateException("Cannot create a new index inside a transaction");
    final Character c = OSchemaShared.checkFieldNameIfValid(iName);
    if (c != null)
        throw new IllegalArgumentException("Invalid index name '" + iName + "'. Character '" + c + "' is invalid");
    ODatabaseInternal database = getDatabase();
    OStorage storage = database.getStorage();
    final Locale locale = getServerLocale();
    type = type.toUpperCase(locale);
    if (algorithm == null) {
        algorithm = OIndexes.chooseDefaultIndexAlgorithm(type);
    }
    final String valueContainerAlgorithm = chooseContainerAlgorithm(type);
    final OIndexInternal<?> index;
    acquireExclusiveLock();
    try {
        if (indexes.containsKey(iName.toLowerCase(locale)))
            throw new OIndexException("Index with name " + iName.toLowerCase(locale) + " already exists.");
        // manual indexes are always durable
        if (clusterIdsToIndex == null || clusterIdsToIndex.length == 0) {
            if (metadata == null)
                metadata = new ODocument().setTrackingChanges(false);
            final Object durable = metadata.field("durableInNonTxMode");
            if (!(durable instanceof Boolean))
                metadata.field("durableInNonTxMode", true);
            if (metadata.field("trackMode") == null)
                metadata.field("trackMode", "FULL");
        }
        index = OIndexes.createIndex(getDatabase(), iName, type, algorithm, valueContainerAlgorithm, metadata, -1);
        if (progressListener == null)
            // ASSIGN DEFAULT PROGRESS LISTENER
            progressListener = new OIndexRebuildOutputListener(index);
        final Set<String> clustersToIndex = findClustersByIds(clusterIdsToIndex, database);
        if (indexDefinition != null) {
            Object ignoreNullValues = metadata == null ? null : metadata.field("ignoreNullValues");
            if (Boolean.TRUE.equals(ignoreNullValues)) {
                indexDefinition.setNullValuesIgnored(true);
            } else if (Boolean.FALSE.equals(ignoreNullValues)) {
                indexDefinition.setNullValuesIgnored(false);
            } else {
                indexDefinition.setNullValuesIgnored(OGlobalConfiguration.INDEX_IGNORE_NULL_VALUES_DEFAULT.getValueAsBoolean());
            }
        }
        // decide which cluster to use ("index" - for automatic and "manindex" for manual)
        final String clusterName = indexDefinition != null && indexDefinition.getClassName() != null ? defaultClusterName : manualClusterName;
        index.create(iName, indexDefinition, clusterName, clustersToIndex, true, progressListener);
        addIndexInternal(index);
        if (metadata != null) {
            final ODocument config = index.getConfiguration();
            config.field("metadata", metadata, OType.EMBEDDED);
        }
        setDirty();
        save();
    } finally {
        releaseExclusiveLock();
    }
    notifyInvolvedClasses(clusterIdsToIndex);
    if (OGlobalConfiguration.INDEX_FLUSH_AFTER_CREATE.getValueAsBoolean())
        storage.synch();
    return preProcessBeforeReturn(index);
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseInternal(com.orientechnologies.orient.core.db.ODatabaseInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OStorage (com.orientechnologies.orient.core.storage.OStorage)90 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)31 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)21 ORecordId (com.orientechnologies.orient.core.id.ORecordId)20 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)18 OPhysicalPosition (com.orientechnologies.orient.core.storage.OPhysicalPosition)12 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)11 File (java.io.File)11 ORID (com.orientechnologies.orient.core.id.ORID)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)7 Test (org.testng.annotations.Test)7 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)6 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)5 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5