The CSLB says a mechanic's lien is: A "hold" against your property, filed by an unpaid contractor, subcontractor, laborer, or material supplier, and is recorded with the county recorder's office. If unpaid, it allows a foreclosure action, forcing the sale of the property in lieu of compensation. https://www.cslb.ca.gov/Consumers/Legal_Issues_For_Consumers/Mechanics_Lien/What_Is_A_Mechanics_Lien.aspx
The mechanic's lien is a form filed with the county recorder of the county the property upon which the work or materials were supplied when one of the people listed in the statute was not paid for the work or materials supplied. It prevents the owner from selling or refinancing the property until the lien is removed. The lien can be bonded around i.e. a bond can be posted which in essence takes the place of the lien and the person supplying the labor or material then can pursue a lawsuit against the bond instead of the property. The lien can also be removed by the contractor releasing the property from the lien. Further, if foreclosure of the lien does not take place within 90 days of its filing the owner can demand release of the lien within ten days via certified mail and if the lien claimant fails to remove the lien the owner can petition the Court to have it removed and if successful the claimant must pay the attorneys fees for the petition.
A number of other factors and conditions go into play to determine if the mechanic's lien is valid. The CSLB explores some of them. https://www.cslb.ca.gov/Consumers/Legal_Issues_For_Consumers/Mechanics_Lien/If_A_Mechanics_Lien_Is_Filed_Against_You.aspx
The definitions and operative statutes regarding mechanic's lien can be found at: https://leginfo.legislature.ca.gov/faces/codes_displayText.xhtml?division=4.&chapter=1.&part=6.&lawCode=CIV&title=1.&article=1.
Owners should be mindful of obtaining Release Forms when making payments to contractors or material suppliers. The CSLB discusses the use of the Conditional and Unconditional Releases and provides exemplar forms for use. https://www.cslb.ca.gov/Consumers/Legal_Issues_For_Consumers/Mechanics_Lien/Conditional_And_Unconditional_Waiver_Release_Form.aspx
The lien must be filed according to the statutory guidelines to be valid and the time runs from the completion of work on the Project or if there is a prolonged cessation of labor on the Project. An attorney should be consulted to determine when the lien should be filed as the guidelines for general (or prime contractors) and subcontractors and material suppliers may differ if a Notice of Completion is filed and served. Prime Contractors are defined in Civil Code 8018: “Direct contractor” means a contractor that has a direct contractual relationship with an owner. A reference in another statute to a “prime contractor” in connection with the provisions in this part means a “direct contractor.” A Subcontractor is defined in Civil Code 8086 as: “Subcontractor” means a contractor that does not have a direct contractual relationship with an owner. The term includes a contractor that has a contractual relationship with a direct contractor or with another subcontractor.
If a Notice of Completion or Notice of Cessation is filed with the County Recorder its a commercial Project then they must give notice of the Completion or Cessation within ten days as required by Civil Code Section 8190. If the Notice not defective, is recorded and served the time for recording a mechanic's lien by the Prime Contractor is 60 days after recordation of the valid Notice of Completion or Cessation and 30 days for all other claimants. However, if a residential owner with not more than four residential units records a Notice of Completion or Cessation then it does not have to be served on the Prime or subcontractors to be effective. Civil Code Section 8190 provides:
https://leginfo.legislature.ca.gov/faces/codes_displaySection.xhtml?sectionNum=8190.&lawCode=CIV
As is obvious this is a difficult area of the law and you should not rely on this post as legal advise and should consult an attorney licensed to practice law in your area.