Separate scanning from counting. Utilize file locking during btree creation.