@Override protected void doStart() throws Exception { Orient.instance().startup(); Orient.instance().removeShutdownHook(); }
public OLuceneIndexFactory(boolean manual) { if (!manual) { Orient.instance().addDbLifecycleListener(this); } }
private void startupIfEnginesAreMissing() { // Using a jdk which doesn't bundle a javascript engine // throws a NoClassDefFoundError while logging the warning // see https://github.com/orientechnologies/orientdb/issues/5855 OLogManager.instance().setWarnEnabled(false); // If an instance of Orient was previously shutdown all engines are removed. // We need to startup Orient again. if (Orient.instance().getEngines().isEmpty()) { Orient.instance().startup(); } OLogManager.instance().setWarnEnabled(true); }
if (iRecord == null || ORecordInternal.getRecordType(iRecord) != fieldValueAsString.charAt(0)) { iRecord = Orient.instance().getRecordFactoryManager().newInstance((byte) fieldValueAsString.charAt(0), -1, ODatabaseRecordThreadLocal.instance().getIfDefined()); ORecord localRecord = ODatabaseRecordThreadLocal.instance().get().load(new ORecordId(fieldValueAsString)); if (localRecord != null) iRecord = localRecord; iRecord = new ODocument(); doc.field(fieldName, v, type); continue; doc.field(fieldName, v, OType.EMBEDDEDMAP); continue;
throw e; } catch (Exception e) { OLogManager.instance().error(this, "Error on using index %s in query '%s'. Probably you need to rebuild indexes. Now executing query using cluster scan", e, index.getName(), request != null && request.getText() != null ? request.getText() : ""); final OProfiler profiler = Orient.instance().getProfiler(); if (profiler.isRecording()) { profiler ((Collection<OIdentifiable>) tempResult).add(new ODocument().field(entry.getKey(), count)); return true;
private void evict() { final long start = Orient.instance().getProfiler().startChrono(); final int initialSize = lruList.size(); int closedFiles = 0; while (lruList.size() > openLimit) { //we may only close items in open state so we "peek" them first Iterator<OClosableEntry<K, V>> iterator = lruList.iterator(); boolean entryClosed = false; while (iterator.hasNext()) { OClosableEntry<K, V> entry = iterator.next(); if (entry.makeClosed()) { closedFiles++; iterator.remove(); entryClosed = true; countClosedFiles(); break; } } //there are no items in open state stop eviction if (!entryClosed) break; } if (closedFiles > 0) { OLogManager.instance().debug(this, "Reached maximum of opened files %d (max=%d), closed %d files. Consider to raise this limit by increasing the global setting '%s' and the OS limit on opened files per processor", initialSize, openLimit, closedFiles, OGlobalConfiguration.OPEN_FILES_LIMIT.getKey()); } Orient.instance().getProfiler() .stopChrono("disk.closeFiles", "Close the opened files because reached the configured limit", start); }
public PageDelegate(WebPage page, ORID pageOrid, ORID docOrid) { this.page = page; this.pageDocumentModel = new ODocumentModel(pageOrid); ODocument doc = (ODocument)(docOrid!=null?docOrid.getRecord():pageDocumentModel.getObject().field(PagesModule.OPROPERTY_DOCUMENT)); if(doc!=null) page.setDefaultModel(new ODocumentModel(doc)); String script = pageDocumentModel.getObject().field(PagesModule.OPROPERTY_SCRIPT); if(!Strings.isEmpty(script)) { OScriptManager scriptManager = Orient.instance().getScriptManager(); ODatabaseDocument db = OrienteerWebSession.get().getDatabase(); final OPartitionedObjectPool.PoolEntry<ScriptEngine> entry =
/** * {@inheritDoc} */ @Override public void freeze(final boolean throwException) { checkOpenness(); if (!(getStorage() instanceof OFreezableStorageComponent)) { OLogManager.instance().error(this, "Only local paginated storage supports freeze. If you are using remote client please use OServerAdmin instead", null); return; } final long startTime = Orient.instance().getProfiler().startChrono(); final OFreezableStorageComponent storage = getFreezableStorage(); if (storage != null) { storage.freeze(throwException); } Orient.instance().getProfiler() .stopChrono("db." + getName() + ".freeze", "Time to freeze the database", startTime, "db.*.freeze"); }
public static boolean encodePassword(final ODocument iDocument) { if (iDocument.field("name") == null) throw new OSecurityException("User name not found"); final String password = (String) iDocument.field("password"); if (password == null) throw new OSecurityException("User '" + iDocument.field("name") + "' has no password"); if (Orient.instance().getSecurity() != null) { Orient.instance().getSecurity().validatePassword(password); } if (!password.startsWith("{")) { iDocument.field("password", encryptPassword(password)); return true; } return false; }
final List<Future<?>> jobs = new ArrayList<Future<?>>(); OLogManager.instance() .debug(this, "Executing parallel query with strategy executors. clusterIds=%d, jobs=%d", clusterIds.length, jobNumbers); contexts[current] = threadContext; localDatabase = db.copy(); localDatabase.activateOnCurrentThread(); db.getMetadata().getSchema().makeSnapshot(); OLogManager.instance().error(this, "Error during command execution", e); jobs.add(Orient.instance().submit(job));
public void handle(final Signal signal) { OLogManager.instance().warn(this, "Received signal: %s", signal); final String s = signal.toString().trim(); if (Orient.instance().isSelfManagedShutdown() && (s.equals("SIGKILL") || s.equals("SIGHUP") || s.equals("SIGINT") || s .equals("SIGTERM"))) { Orient.instance().shutdown(); System.exit(1); } else if (s.equals("SIGTRAP")) { System.out.println(); OGlobalConfiguration.dumpConfiguration(System.out); System.out.println(); Orient.instance().getProfiler().dump(System.out); System.out.println(); System.out.println(Orient.instance().getProfiler().threadDump()); } else { SignalHandler redefinedHandler = redefinedHandlers.get(signal); if (redefinedHandler != null) { redefinedHandler.handle(signal); } } for (OSignalListener l : listeners) l.onSignal(signal); }
public void testOrientDbLifeCycle(String dbURL, boolean createDb, boolean dropDb) throws Exception { Orient.instance().startup(); assertNotNull(ODatabaseRecordThreadLocal.instance()); Orient.instance().removeShutdownHook(); OServer server = OServerMain.create(); server.startup(OrientDbTestWebApplication.class.getResource("db.config.xml").openStream()); server.activate(); if(createDb) { ODatabaseDocument dbToCreate = new ODatabaseDocumentTx(dbURL); if(!dbToCreate.exists()) dbToCreate.create(); dbToCreate.close(); } assertNotNull(ODatabaseRecordThreadLocal.instance()); ODatabaseDocument db = new OPartitionedDatabasePoolFactory().get(dbURL, "admin", "admin").acquire(); db.close(); assertNotNull(ODatabaseRecordThreadLocal.instance()); if(dropDb) { ODatabaseDocument dbToDrop = new ODatabaseDocumentTx(dbURL); dbToDrop.open("admin", "admin"); dbToDrop.drop(); } server.shutdown(); Orient.instance().shutdown(); // Thread.sleep(50); }
public void callOnOpenListeners() { // WAKE UP DB LIFECYCLE LISTENER for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onOpen(getDatabaseOwner()); // WAKE UP LISTENERS for (ODatabaseListener listener : getListenersCopy()) try { listener.onOpen(getDatabaseOwner()); } catch (Exception e) { OLogManager.instance().error(this, "Error during call of database listener", e); } }
private OClass doCreateClass(ODatabaseDocumentInternal database, final String className, final int clusters, OClass... superClasses) { OClass result; database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE); if (superClasses != null) OClassImpl.checkParametersConflict(Arrays.asList(superClasses)); final OStorage storage = database.getStorage(); StringBuilder cmd = new StringBuilder("create class "); cmd.append('`'); commandSQL.addExcludedNode(autoshardedStorage.getNodeId()); final Object res = database.command(commandSQL).execute(); for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreateClass(database, result);
return iCurrent.getRecord().getVersion(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_CLASS)) return ((ODocument) iCurrent.getRecord()).getClassName(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_TYPE)) return Orient.instance().getRecordFactoryManager().getRecordTypeName(ORecordInternal.getRecordType(iCurrent.getRecord())); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_SIZE)) { final byte[] stream = iCurrent.getRecord().toStream(); return stream != null ? stream.length : 0; } else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_FIELDS)) return ((ODocument) iCurrent.getRecord()).fieldNames(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_RAW)) return new String(iCurrent.getRecord().toStream()); return null; doc.checkForFields(iFieldName); ODocumentEntry entry = doc._fields.get(iFieldName); return entry != null ? entry.value : null;
final long jvmMaxMemory = Runtime.getRuntime().maxMemory(); for (OStorage s : Orient.instance().getStorages()) { if (s instanceof OLocalPaginatedStorage) { final OReadCache dk = ((OLocalPaginatedStorage) s).getReadCache(); OGlobalConfiguration.DISK_CACHE_SIZE.getValueAsLong() + (jvmMaxMemory - suggestedMaxHeap) / OFileUtils.MEGABYTE; OLogManager.instance().info(this, "Database '%s' uses %,dMB/%,dMB of DISKCACHE memory, while Heap is not completely used (usedHeap=%dMB maxHeap=%dMB). To improve performance set maxHeap to %dMB and DISKCACHE to %dMB", s.getName(), totalDiskCacheUsedMemory, maxDiskCacheUsedMemory, jvmTotMemory / OFileUtils.MEGABYTE, jvmMaxMemory / OFileUtils.MEGABYTE, suggestedMaxHeap / OFileUtils.MEGABYTE, suggestedDiskCache); OLogManager.instance().info(this, "-> Open server.sh (or server.bat on Windows) and change the following variables: 1) MAXHEAP=-Xmx%dM 2) MAXDISKCACHE=%d", suggestedMaxHeap / OFileUtils.MEGABYTE, suggestedDiskCache);
OLogManager.instance().info(this, "Orient Engine is shutting down..."); for (OShutdownHandler handler : shutdownHandlers) { try { OLogManager.instance().debug(this, "Shutdown handler %s is going to be called", handler); handler.shutdown(); OLogManager.instance().debug(this, "Shutdown handler %s completed", handler); } finally { try { removeShutdownHook(); } finally { try { removeSignalHandler(); } finally { engineLock.writeLock().unlock();
@Override public void setAutoDump(final int iSeconds) { if (autoDumpTask != null) { // CANCEL ANY PREVIOUS RUNNING TASK autoDumpTask.cancel(); autoDumpTask = null; } if (iSeconds > 0) { OLogManager.instance().info(this, "Enabled auto dump of profiler every %d second(s)", iSeconds); final int ms = iSeconds * 1000; autoDumpTask = new TimerTask() { @Override public void run() { final StringBuilder output = new StringBuilder(); final String dumpType = OGlobalConfiguration.PROFILER_AUTODUMP_TYPE.getValueAsString(); output.append( "\n*******************************************************************************************************************************************"); output.append("\nPROFILER AUTO DUMP '" + dumpType + "' OUTPUT (to disabled it set 'profiler.autoDump.interval' = 0):\n"); output.append(dump(dumpType)); output.append( "\n*******************************************************************************************************************************************"); OLogManager.instance().info(null, output.toString()); } }; Orient.instance().scheduleTask(autoDumpTask, ms, ms); } else OLogManager.instance().info(this, "Auto dump of profiler disabled", iSeconds); }