瀏覽代碼

Test acquire failover
Author: jgg
Date: 1998-12-11 06:01:23 GMT
Test acquire failover

Arch Librarian 22 年之前
父節點
當前提交
b185acc2d3
共有 4 個文件被更改,包括 65 次插入42 次删除
  1. 24 20
      apt-pkg/acquire-item.cc
  2. 7 1
      apt-pkg/acquire-item.h
  3. 31 20
      apt-pkg/acquire.cc
  4. 3 1
      apt-pkg/acquire.h

+ 24 - 20
apt-pkg/acquire-item.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: acquire-item.cc,v 1.15 1998/12/11 04:47:50 jgg Exp $
+// $Id: acquire-item.cc,v 1.16 1998/12/11 06:01:23 jgg Exp $
 /* ######################################################################
 
    Acquire Item - Item to acquire
@@ -9,7 +9,7 @@
    cannot create an item that fetches two uri's to two files at the same 
    time. The pkgAcqIndex class creates a second class upon instantiation
    to fetch the other index files because of this.
-   
+
    ##################################################################### */
 									/*}}}*/
 // Include Files							/*{{{*/
@@ -336,10 +336,20 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
 			     pkgRecords *Recs,pkgCache::VerIterator const &Version,
 			     string &StoreFilename) :
                Item(Owner), Version(Version), Sources(Sources), Recs(Recs), 
-               StoreFilename(StoreFilename)
+               StoreFilename(StoreFilename), Vf(Version.FileList())
 {
    // Select a source
-   pkgCache::VerFileIterator Vf = Version.FileList();
+   if (QueueNext() == false && _error->PendingError() == false)
+      _error->Error("I wasn't able to locate file for the %s package. "
+		    "This might mean you need to manually fix this package.",
+		    Version.ParentPkg().Name());
+}
+									/*}}}*/
+// AcqArchive::QueueNext - Queue the next file source			/*{{{*/
+// ---------------------------------------------------------------------
+/* This queues the next available file version for download. */
+bool pkgAcqArchive::QueueNext()
+{
    for (; Vf.end() == false; Vf++)
    {
       // Ignore not source sources
@@ -359,17 +369,14 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
       // Grab the text package record
       pkgRecords::Parser &Parse = Recs->Lookup(Vf);
       if (_error->PendingError() == true)
-	 return;
+	 return false;
       
       PkgFile = Parse.FileName();
       MD5 = Parse.MD5Hash();
       if (PkgFile.empty() == true)
-      {
-	 _error->Error("I need to reinstall package %s to fix it but I "
-		       "can't find a file for it! You must deal with "
-		       "this by hand.",Version.ParentPkg().Name());
-	 return;
-      }
+	 return _error->Error("The package index files are corrupted. No Filename: "
+			      "field for package %s."
+			      ,Version.ParentPkg().Name());
 
       // See if we already have the file.
       FileSize = Version->Size;
@@ -384,7 +391,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
 	    Local = true;
 	    Status = StatDone;
 	    StoreFilename = DestFile = FinalFile;
-	    return;
+	    return true;
 	 }
 	 
 	 /* Hmm, we have a file and its size does not match, this shouldnt
@@ -400,14 +407,12 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
       Desc.Owner = this;
       Desc.ShortDesc = Version.ParentPkg().Name();
       QueueURI(Desc);
-      
-      return;
+
+      Vf++;
+      return true;
    }
-   
-  _error->Error("I wasn't able to locate file for the %s package. "
-		"This probably means you need to rerun update.",
-		Version.ParentPkg().Name());
-}
+   return false;
+}   
 									/*}}}*/
 // AcqArchive::Done - Finished fetching					/*{{{*/
 // ---------------------------------------------------------------------
@@ -469,4 +474,3 @@ string pkgAcqArchive::Describe()
    return Desc.URI;
 }
 									/*}}}*/
-

+ 7 - 1
apt-pkg/acquire-item.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: acquire-item.h,v 1.10 1998/11/22 03:20:31 jgg Exp $
+// $Id: acquire-item.h,v 1.11 1998/12/11 06:01:25 jgg Exp $
 /* ######################################################################
 
    Acquire Item - Item to acquire
@@ -12,6 +12,9 @@
    Two item classes are provided to provide functionality for downloading
    of Index files and downloading of Packages.
    
+   A Archive class is provided for downloading .deb files. It does Md5
+   checking and source location.
+   
    ##################################################################### */
 									/*}}}*/
 #ifndef PKGLIB_ACQUIRE_ITEM_H
@@ -111,6 +114,9 @@ class pkgAcqArchive : public pkgAcquire::Item
    pkgRecords *Recs;
    string MD5;
    string &StoreFilename;
+   pkgCache::VerFileIterator Vf;
+   
+   bool QueueNext();
    
    public:
    

+ 31 - 20
apt-pkg/acquire.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: acquire.cc,v 1.20 1998/12/05 04:19:03 jgg Exp $
+// $Id: acquire.cc,v 1.21 1998/12/11 06:01:26 jgg Exp $
 /* ######################################################################
 
    Acquire - File Acquiration
@@ -436,6 +436,8 @@ pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : Name(Name),
    Items = 0;
    Next = 0;
    Workers = 0;
+   MaxPipeDepth = 1;
+   PipeDepth = 0;
 }
 									/*}}}*/
 // Queue::~Queue - Destructor						/*{{{*/
@@ -474,9 +476,12 @@ void pkgAcquire::Queue::Enqueue(ItemDesc &Item)
 									/*}}}*/
 // Queue::Dequeue - Remove an item from the queue			/*{{{*/
 // ---------------------------------------------------------------------
-/* We return true if we hit something*/
+/* We return true if we hit something */
 bool pkgAcquire::Queue::Dequeue(Item *Owner)
 {
+   if (Owner->Status == pkgAcquire::Item::StatFetching)
+      return _error->Error("Tried to dequeue a fetching object");
+       
    bool Res = false;
    
    QItem **I = &Items;
@@ -518,12 +523,9 @@ bool pkgAcquire::Queue::Startup()
       added other source retry to have cycle maintain a pipeline depth
       on its own. */
    if (Cnf->Pipeline == true)
-   {
-      bool Res = true;
-      for (int I = 0; I != 10 && Res == true; I++)
-	 Res &= Cycle();
-      return Res;
-   }
+      MaxPipeDepth = 10;
+   else
+      MaxPipeDepth = 1;
    
    return Cycle();
 }
@@ -563,6 +565,7 @@ pkgAcquire::Queue::QItem *pkgAcquire::Queue::FindItem(string URI,pkgAcquire::Wor
    main queue too.*/
 bool pkgAcquire::Queue::ItemDone(QItem *Itm)
 {
+   PipeDepth--;
    if (Itm->Owner->QueueCounter <= 1)
       Owner->Dequeue(Itm->Owner);
    else
@@ -576,7 +579,8 @@ bool pkgAcquire::Queue::ItemDone(QItem *Itm)
 									/*}}}*/
 // Queue::Cycle - Queue new items into the method			/*{{{*/
 // ---------------------------------------------------------------------
-/* This locates a new idle item and sends it to the worker */
+/* This locates a new idle item and sends it to the worker. If pipelining
+   is enabled then it keeps the pipe full. */
 bool pkgAcquire::Queue::Cycle()
 {
    if (Items == 0 || Workers == 0)
@@ -584,24 +588,31 @@ bool pkgAcquire::Queue::Cycle()
 
    // Look for a queable item
    QItem *I = Items;
-   for (; I != 0; I = I->Next)
-      if (I->Owner->Status == pkgAcquire::Item::StatIdle)
-	 break;
-
-   // Nothing to do, queue is idle.
-   if (I == 0)
-      return true;
+   while (PipeDepth < MaxPipeDepth)
+   {
+      for (; I != 0; I = I->Next)
+	 if (I->Owner->Status == pkgAcquire::Item::StatIdle)
+	    break;
+      
+      // Nothing to do, queue is idle.
+      if (I == 0)
+	 return true;
+      
+      I->Worker = Workers;
+      I->Owner->Status = pkgAcquire::Item::StatFetching;
+      if (Workers->QueueItem(I) == false)
+	 return false;
+   }
    
-   I->Worker = Workers;
-   I->Owner->Status = pkgAcquire::Item::StatFetching;
-   return Workers->QueueItem(I);
+   return true;
 }
 									/*}}}*/
 // Queue::Bump - Fetch any pending objects if we are idle		/*{{{*/
 // ---------------------------------------------------------------------
-/* */
+/* This is called when an item in multiple queues is dequeued */
 void pkgAcquire::Queue::Bump()
 {
+   Cycle();
 }
 									/*}}}*/
 

+ 3 - 1
apt-pkg/acquire.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: acquire.h,v 1.16 1998/12/04 21:16:49 jgg Exp $
+// $Id: acquire.h,v 1.17 1998/12/11 06:01:27 jgg Exp $
 /* ######################################################################
 
    Acquire - File Acquiration
@@ -149,6 +149,8 @@ class pkgAcquire::Queue
    QItem *Items;
    pkgAcquire::Worker *Workers;
    pkgAcquire *Owner;
+   unsigned long PipeDepth;
+   unsigned long MaxPipeDepth;
    
    public: