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/jit/writing-background]])
Here "sword" represents being killed by the angel of Yahweh. Alternate translation: "afraid he would be killed by the angel of Yahweh" (See: [[rc://en/ta/man/jit/figs-metonymy]])