Verses 29-30 are background information to explain why David offered this sacrifice at the threshing floor instead of on the altar at the tabernacle. (See: [[rc://en/ta/man/translate/writing-background]])
Here "sword" represents being killed by the angel of Yahweh. AT: "afraid he would be killed by the angel of Yahweh" (See: [[rc://en/ta/man/translate/figs-metonymy]])