PostgreSQL变频机制

  

<强>

<强>

malloc

PostgresMain→BaseInit→InitFileAccess:   VfdCache=(*)变频malloc (sizeof (Vfd));   MemSet ((char *)和(VfdCache [0]), 0, sizeof (Vfd));   VfdCache→fd=VFD_CLOSED;   SizeVfdCache=1;

<强>

PathNameOpenFilePerm→   文件=AllocateVfd ();   vfdP=, VfdCache[文件];   ReleaseLruFiles ();   vfdP→fd=BasicOpenFilePerm(文件名、fileFlags fileMode);   插入(文件);   vfdP→文件名=fnamecopy;/*保存旗帜调整好重启文件*/vfdP→fileFlags=fileFlags和;~ (O_CREAT | O_TRUNC | O_EXCL);   vfdP→fileMode=fileMode;   vfdP→文件大?0;   vfdP→fdstate=0 x0;   vfdP→复种=零;

<强>

AllocateVfd→   如果(VfdCache [0]。nextFree==0) {   大小newCacheSize=SizeVfdCache * 2;   如果(newCacheSize & lt;32)   newCacheSize=32;   newVfdCache=(*)变频realloc (VfdCache sizeof (Vfd) * newCacheSize);   VfdCache=newVfdCache;   (我=SizeVfdCache;我& lt;newCacheSize;我+ +){   MemSet ((char *)和(VfdCache[我]),0,sizeof (Vfd));   VfdCache[我]。nextFree=i + 1;   VfdCache[我]。fd=VFD_CLOSED;   }   VfdCache [newCacheSize - 1]。nextFree=0;   VfdCache [0]。nextFree=SizeVfdCache;   SizeVfdCache=newCacheSize;   }   文件=VfdCache [0] .nextFree;   VfdCache [0]。nextFree=VfdCache[文件].nextFree;   返回文件;

 PostgreSQL变频机制

<强>

fdVFD_CLOSED

ReleaseLruFiles→   而(nfile + numAllocatedDescs祝辞=max_safe_fds) {   如果(! ReleaseLruFile ())   打破;   }
插入→
  vfdP=, VfdCache[文件];
  vfdP→lruMoreRecently=0;
  vfdP→lruLe * * *其=VfdCache [0] .lruLe * * *其;
  VfdCache [0]。lruLe * * *其=文件;
  VfdCache [vfdP→lruLe * * *其]。lruMoreRecently=文件;

 PostgreSQL变频机制

 PostgreSQL变频机制

<强>

删除(文件);——比;   vfdP=, VfdCache[文件];   VfdCache [vfdP→lruLe * * *其]。lruMoreRecently=vfdP→lruMoreRecently;   VfdCache [vfdP→lruMoreRecently]。lruLe * * *其=vfdP→lruLe * * *其;

VfdCache [1]

 PostgreSQL变频机制

<强>

FileClose→   关闭(vfdP→fd);   ——nfile;   vfdP→fd=VFD_CLOSED;   删除(文件);   …   FreeVfd(文件);

<强>

FreeVfd

FreeVfd→   免费(vfdP→文件名);//注意文件名需要释放,他是另malloc的   vfdP→文件名=零;   vfdP→fdstate=0 x0;   vfdP→nextFree=VfdCache [0] .nextFree;   VfdCache [0]。nextFree=文件;


PostgreSQL变频机制