private void PopulateDefaultCachedObjects(Schema.Catalog defaultCachedObjects) { foreach (Schema.Object objectValue in defaultCachedObjects) { _cachedObjects.Add(objectValue); } }
private void InternalCreateCatalog() { _catalog = new Schema.Catalog(); _planCache = new PlanCache(DefaultPlanCacheSize); if (_streamManager == null) { _streamManager = new ServerStreamManager(this); } }
private void CatalogLookupFailed(Schema.Catalog catalog, string name) { #if LOGCACHEEVENTS FSession.FServer.FInternalServer.LogMessage(String.Format("Retrieving catalog for '{0}'.", AName)); #endif // A cache miss forces the retrieval of the datatype and its dependencies from the remote server process long cacheTimeStamp; long clientCacheTimeStamp; bool cacheChanged; string stringValue = _process.GetCatalog(name, out cacheTimeStamp, out clientCacheTimeStamp, out cacheChanged); // Ensure that the local cache is consistent before adding to the cache if (cacheChanged) { try { _session._server.WaitForCacheTimeStamp(this, clientCacheTimeStamp - 1); _session._server.AcquireCacheLock(this, LockMode.Exclusive); try { _session._server.EnsureCacheConsistent(cacheTimeStamp); if (stringValue != String.Empty) { IServerScript script = ((IServerProcess)_internalProcess).PrepareScript(stringValue); try { script.Execute(null); } finally { ((IServerProcess)_internalProcess).UnprepareScript(script); } } } finally { _session._server.ReleaseCacheLock(this, LockMode.Exclusive); } } catch (Exception E) { // Notify the server that the client cache is out of sync Execute(".System.UpdateTimeStamps();", null); E = new ServerException(ServerException.Codes.CacheDeserializationError, E, clientCacheTimeStamp); _session._server._internalServer.LogError(E); throw E; } finally { _session._server.SetCacheTimeStamp(this, clientCacheTimeStamp); } } }
public bool EnsureConsistent(long cacheTimeStamp, Schema.Catalog defaultCachedObjects) { if (cacheTimeStamp > _cacheTimeStamp) { _cachedObjects.Clear(); _cacheTimeStamp = cacheTimeStamp; PopulateDefaultCachedObjects(defaultCachedObjects); UpdateTimeStamp(); return(true); } return(false); }
public void EnsureCacheConsistent(long serverCacheTimeStamp) { if (_serverCacheTimeStamp < serverCacheTimeStamp) { DoCacheClearing(); Schema.Catalog catalog = _internalServer.Catalog; var catalogDevice = _internalServer.CatalogDevice; _internalServer.ClearCatalog(); foreach (Schema.RegisteredAssembly assembly in catalog.ClassLoader.Assemblies) { if (assembly.Library.Name != Engine.SystemLibraryName) { _internalServer.Catalog.ClassLoader.Assemblies.Add(assembly); } } foreach (Schema.RegisteredClass classValue in catalog.ClassLoader.Classes) { if (!_internalServer.Catalog.ClassLoader.Classes.Contains(classValue)) { _internalServer.Catalog.ClassLoader.Classes.Add(classValue); } } foreach (ServerSession session in _internalServer.Sessions) { if (session.User.ID == _internalServer.SystemUser.ID) { session.SetUser(_internalServer.SystemUser); } if (session.User.ID == _internalServer.AdminUser.ID) { session.SetUser(_internalServer.AdminUser); } session.SessionObjects.Clear(); foreach (ServerProcess process in session.Processes) { process.DeviceDisconnect(catalogDevice); } } _serverCacheTimeStamp = serverCacheTimeStamp; DoCacheCleared(); } }
public string GetCatalog(string name, out long cacheTimeStamp, out long clientCacheTimeStamp, out bool cacheChanged) { cacheTimeStamp = _serverProcess.ServerSession.Server.CacheTimeStamp; Schema.Catalog catalog = new Schema.Catalog(); catalog.IncludeDependencies(_serverProcess.CatalogDeviceSession, _serverProcess.Catalog, _serverProcess.Catalog[name], EmitMode.ForRemote); #if LOGCACHEEVENTS FServerProcess.ServerSession.Server.LogMessage(String.Format("Getting catalog for data type '{0}'.", AName)); #endif cacheChanged = true; string[] requiredObjects = _session.Server.CatalogCaches.GetRequiredObjects(_session, catalog, cacheTimeStamp, out clientCacheTimeStamp); if (requiredObjects.Length > 0) { string catalogString = new D4TextEmitter(EmitMode.ForRemote).Emit(catalog.EmitStatement(_serverProcess.CatalogDeviceSession, EmitMode.ForRemote, requiredObjects)); return(catalogString); } return(String.Empty); }
public string[] GetRequiredObjects(RemoteServerSession session, Schema.Catalog catalog, long cacheTimeStamp, out long clientCacheTimeStamp) { List <string> requiredObjects = new List <string>(); CatalogCache cache = (CatalogCache)_caches[session.CatalogCacheName]; lock (cache) { bool cacheChanged = cache.EnsureConsistent(cacheTimeStamp, _defaultCachedObjects); foreach (Schema.Object objectValue in catalog) { if (!cache.CachedObjects.ContainsName(objectValue.Name)) { if (!((objectValue is Schema.DerivedTableVar) && (objectValue.Name == ((Schema.DerivedTableVar)objectValue).SessionObjectName))) { cache.CachedObjects.Add(objectValue); } requiredObjects.Add(objectValue.Name); } } if (!cacheChanged) { cache.UpdateTimeStamp(); } clientCacheTimeStamp = cache.TimeStamp; } string[] result = new string[requiredObjects.Count]; requiredObjects.CopyTo(result, 0); #if LOGCACHEEVENTS ASession.Server.LogMessage(String.Format("Session {0} cache timestamp updated to {1} with required objects: {2}", ASession.SessionID.ToString(), AClientCacheTimeStamp.ToString(), ExceptionUtility.StringsToCommaList(requiredObjects))); #endif return(result); }
public CatalogCache(string cacheName, long cacheTimeStamp, Schema.Catalog defaultCachedObjects) : base() { _cacheName = cacheName; _cacheTimeStamp = cacheTimeStamp; PopulateDefaultCachedObjects(defaultCachedObjects); }