@@ -105,10 +105,10 @@ func (m *Manifest) asChanges() []*pb.ManifestChange {
105105 return changes
106106}
107107
108- func (m * Manifest ) clone () Manifest {
108+ func (m * Manifest ) clone (opt Options ) Manifest {
109109 changeSet := pb.ManifestChangeSet {Changes : m .asChanges ()}
110110 ret := createManifest ()
111- y .Check (applyChangeSet (& ret , & changeSet ))
111+ y .Check (applyChangeSet (& ret , & changeSet , opt ))
112112 return ret
113113}
114114
@@ -120,11 +120,11 @@ func openOrCreateManifestFile(opt Options) (
120120 return & manifestFile {inMemory : true }, Manifest {}, nil
121121 }
122122 return helpOpenOrCreateManifestFile (opt .Dir , opt .ReadOnly , opt .ExternalMagicVersion ,
123- manifestDeletionsRewriteThreshold )
123+ manifestDeletionsRewriteThreshold , opt )
124124}
125125
126126func helpOpenOrCreateManifestFile (dir string , readOnly bool , extMagic uint16 ,
127- deletionsThreshold int ) (* manifestFile , Manifest , error ) {
127+ deletionsThreshold int , opt Options ) (* manifestFile , Manifest , error ) {
128128
129129 path := filepath .Join (dir , ManifestFilename )
130130 var flags y.Flags
@@ -149,13 +149,13 @@ func helpOpenOrCreateManifestFile(dir string, readOnly bool, extMagic uint16,
149149 fp : fp ,
150150 directory : dir ,
151151 externalMagic : extMagic ,
152- manifest : m .clone (),
152+ manifest : m .clone (opt ),
153153 deletionsRewriteThreshold : deletionsThreshold ,
154154 }
155155 return mf , m , nil
156156 }
157157
158- manifest , truncOffset , err := ReplayManifestFile (fp , extMagic )
158+ manifest , truncOffset , err := ReplayManifestFile (fp , extMagic , opt )
159159 if err != nil {
160160 _ = fp .Close ()
161161 return nil , Manifest {}, err
@@ -177,7 +177,7 @@ func helpOpenOrCreateManifestFile(dir string, readOnly bool, extMagic uint16,
177177 fp : fp ,
178178 directory : dir ,
179179 externalMagic : extMagic ,
180- manifest : manifest .clone (),
180+ manifest : manifest .clone (opt ),
181181 deletionsRewriteThreshold : deletionsThreshold ,
182182 }
183183 return mf , manifest , nil
@@ -194,7 +194,7 @@ func (mf *manifestFile) close() error {
194194// we replay the MANIFEST file, we'll either replay all the changes or none of them. (The truth of
195195// this depends on the filesystem -- some might append garbage data if a system crash happens at
196196// the wrong time.)
197- func (mf * manifestFile ) addChanges (changesParam []* pb.ManifestChange ) error {
197+ func (mf * manifestFile ) addChanges (changesParam []* pb.ManifestChange , opt Options ) error {
198198 if mf .inMemory {
199199 return nil
200200 }
@@ -207,7 +207,7 @@ func (mf *manifestFile) addChanges(changesParam []*pb.ManifestChange) error {
207207 // Maybe we could use O_APPEND instead (on certain file systems)
208208 mf .appendLock .Lock ()
209209 defer mf .appendLock .Unlock ()
210- if err := applyChangeSet (& mf .manifest , & changes ); err != nil {
210+ if err := applyChangeSet (& mf .manifest , & changes , opt ); err != nil {
211211 return err
212212 }
213213 // Rewrite manifest if it'd shrink by 1/10 and it's big enough to care
@@ -350,7 +350,7 @@ var (
350350// Also, returns the last offset after a completely read manifest entry -- the file must be
351351// truncated at that point before further appends are made (if there is a partial entry after
352352// that). In normal conditions, truncOffset is the file size.
353- func ReplayManifestFile (fp * os.File , extMagic uint16 ) (Manifest , int64 , error ) {
353+ func ReplayManifestFile (fp * os.File , extMagic uint16 , opt Options ) (Manifest , int64 , error ) {
354354 r := countingReader {wrapped : bufio .NewReader (fp )}
355355
356356 var magicBuf [8 ]byte
@@ -418,15 +418,15 @@ func ReplayManifestFile(fp *os.File, extMagic uint16) (Manifest, int64, error) {
418418 return Manifest {}, 0 , err
419419 }
420420
421- if err := applyChangeSet (& build , & changeSet ); err != nil {
421+ if err := applyChangeSet (& build , & changeSet , opt ); err != nil {
422422 return Manifest {}, 0 , err
423423 }
424424 }
425425
426426 return build , offset , nil
427427}
428428
429- func applyManifestChange (build * Manifest , tc * pb.ManifestChange ) error {
429+ func applyManifestChange (build * Manifest , tc * pb.ManifestChange , opt Options ) error {
430430 switch tc .Op {
431431 case pb .ManifestChange_CREATE :
432432 if _ , ok := build .Tables [tc .Id ]; ok {
@@ -445,10 +445,14 @@ func applyManifestChange(build *Manifest, tc *pb.ManifestChange) error {
445445 case pb .ManifestChange_DELETE :
446446 tm , ok := build .Tables [tc .Id ]
447447 if ! ok {
448- return fmt .Errorf ("MANIFEST removes non-existing table %d" , tc .Id )
448+ opt .Warningf ("MANIFEST delete: table %d has already been removed" , tc .Id )
449+ for _ , level := range build .Levels {
450+ delete (level .Tables , tc .Id )
451+ }
452+ } else {
453+ delete (build .Levels [tm .Level ].Tables , tc .Id )
454+ delete (build .Tables , tc .Id )
449455 }
450- delete (build .Levels [tm .Level ].Tables , tc .Id )
451- delete (build .Tables , tc .Id )
452456 build .Deletions ++
453457 default :
454458 return fmt .Errorf ("MANIFEST file has invalid manifestChange op" )
@@ -458,9 +462,9 @@ func applyManifestChange(build *Manifest, tc *pb.ManifestChange) error {
458462
459463// This is not a "recoverable" error -- opening the KV store fails because the MANIFEST file is
460464// just plain broken.
461- func applyChangeSet (build * Manifest , changeSet * pb.ManifestChangeSet ) error {
465+ func applyChangeSet (build * Manifest , changeSet * pb.ManifestChangeSet , opt Options ) error {
462466 for _ , change := range changeSet .Changes {
463- if err := applyManifestChange (build , change ); err != nil {
467+ if err := applyManifestChange (build , change , opt ); err != nil {
464468 return err
465469 }
466470 }
0 commit comments