use lock to fix duplicate primary key