remove partitions from metadata and fix a bug in getting the max partition